{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/publishing-api/pulls/comments/92619095","pull_request_review_id":13138219,"id":92619095,"diff_hunk":"@@ -0,0 +1,123 @@\n+module Commands\n+  module V2\n+    class Import < BaseCommand\n+      def call\n+        unless UuidValidator.valid?(payload[:content_id])\n+          raise CommandError.new(\n+          code: 422,\n+          error_details: {\n+            error: {\n+              code: 422,\n+              message: \"Content id not valid\",\n+              fields: \"content_id\",\n+            }\n+          })\n+        end\n+\n+        delete_all(payload[:content_id])\n+        all_content_items.map.with_index do |event, index|\n+          create_content_item(event, index, payload[:content_id])\n+        end\n+\n+        after_transaction_commit do\n+          send_downstream(all_content_items.find { |e| e[:action] == 'Publish' })\n+        end\n+\n+        Success.new(content_id: payload[:content_id])\n+      end\n+\n+    private\n+\n+      def all_content_items\n+        @all_content_items ||= [redirects.compact + payload[:content_items]].flatten\n+      end\n+\n+      def send_downstream(content)\n+        return unless content\n+        DownstreamLiveWorker.perform_async_in_queue(\n+          DownstreamLiveWorker::LOW_QUEUE,\n+          content_id: content[:content_id],\n+          locale: 'en',\n+          message_queue_update_type: content[:payload][:update_type],\n+          payload_version: event.id","path":"app/commands/v2/import.rb","position":42,"original_position":42,"commit_id":"bdfcf34573633f2fe1ee8fc9f065878ad2b84501","original_commit_id":"bdfcf34573633f2fe1ee8fc9f065878ad2b84501","user":{"login":"binaryberry","id":8225167,"avatar_url":"https://avatars.githubusercontent.com/u/8225167?v=3","gravatar_id":"","url":"https://api.github.com/users/binaryberry","html_url":"https://github.com/binaryberry","followers_url":"https://api.github.com/users/binaryberry/followers","following_url":"https://api.github.com/users/binaryberry/following{/other_user}","gists_url":"https://api.github.com/users/binaryberry/gists{/gist_id}","starred_url":"https://api.github.com/users/binaryberry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/binaryberry/subscriptions","organizations_url":"https://api.github.com/users/binaryberry/orgs","repos_url":"https://api.github.com/users/binaryberry/repos","events_url":"https://api.github.com/users/binaryberry/events{/privacy}","received_events_url":"https://api.github.com/users/binaryberry/received_events","type":"User","site_admin":false},"body":"We don't expect there to be any redirects for needs. The way the rake task in govuk_need_api is being built, all versions of a Need have the [same base_path](https://github.com/alphagov/govuk_need_api/pull/114/files#diff-e6b7dadd98f8ffc2590ab131f4e70755R89). There is no functionality to redirect from one need to another in Maslow either.","created_at":"2016-12-15T14:31:50Z","updated_at":"2016-12-15T14:31:50Z","html_url":"https://github.com/alphagov/publishing-api/pull/622#discussion_r92619095","pull_request_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/622","_links":{"self":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/comments/92619095"},"html":{"href":"https://github.com/alphagov/publishing-api/pull/622#discussion_r92619095"},"pull_request":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/622"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/publishing-api/pulls/622","id":96547139,"html_url":"https://github.com/alphagov/publishing-api/pull/622","diff_url":"https://github.com/alphagov/publishing-api/pull/622.diff","patch_url":"https://github.com/alphagov/publishing-api/pull/622.patch","issue_url":"https://api.github.com/repos/alphagov/publishing-api/issues/622","number":622,"state":"open","locked":false,"title":"Import history","user":{"login":"cbaines","id":1130010,"avatar_url":"https://avatars.githubusercontent.com/u/1130010?v=3","gravatar_id":"","url":"https://api.github.com/users/cbaines","html_url":"https://github.com/cbaines","followers_url":"https://api.github.com/users/cbaines/followers","following_url":"https://api.github.com/users/cbaines/following{/other_user}","gists_url":"https://api.github.com/users/cbaines/gists{/gist_id}","starred_url":"https://api.github.com/users/cbaines/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbaines/subscriptions","organizations_url":"https://api.github.com/users/cbaines/orgs","repos_url":"https://api.github.com/users/cbaines/repos","events_url":"https://api.github.com/users/cbaines/events{/privacy}","received_events_url":"https://api.github.com/users/cbaines/received_events","type":"User","site_admin":false},"body":"https://trello.com/c/7LsjNZM2/802-add-endpoints-for-importing-content-in-to-the-publishing-api-3\r\n\r\nI'm looking at this as part of the work on importing Needs in to the Publishing API.","created_at":"2016-12-05T15:16:37Z","updated_at":"2016-12-15T14:31:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9e40d3fe608b84ae4eefe0e83f931f1146718942","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/622/commits","review_comments_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/622/comments","review_comment_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/publishing-api/issues/622/comments","statuses_url":"https://api.github.com/repos/alphagov/publishing-api/statuses/bdfcf34573633f2fe1ee8fc9f065878ad2b84501","head":{"label":"alphagov:import_history","ref":"import_history","sha":"bdfcf34573633f2fe1ee8fc9f065878ad2b84501","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":27546098,"name":"publishing-api","full_name":"alphagov/publishing-api","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/publishing-api","description":"Central store for all content on GOV.UK.","fork":false,"url":"https://api.github.com/repos/alphagov/publishing-api","forks_url":"https://api.github.com/repos/alphagov/publishing-api/forks","keys_url":"https://api.github.com/repos/alphagov/publishing-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/publishing-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/publishing-api/teams","hooks_url":"https://api.github.com/repos/alphagov/publishing-api/hooks","issue_events_url":"https://api.github.com/repos/alphagov/publishing-api/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/publishing-api/events","assignees_url":"https://api.github.com/repos/alphagov/publishing-api/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/publishing-api/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/publishing-api/tags","blobs_url":"https://api.github.com/repos/alphagov/publishing-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/publishing-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/publishing-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/publishing-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/publishing-api/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/publishing-api/languages","stargazers_url":"https://api.github.com/repos/alphagov/publishing-api/stargazers","contributors_url":"https://api.github.com/repos/alphagov/publishing-api/contributors","subscribers_url":"https://api.github.com/repos/alphagov/publishing-api/subscribers","subscription_url":"https://api.github.com/repos/alphagov/publishing-api/subscription","commits_url":"https://api.github.com/repos/alphagov/publishing-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/publishing-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/publishing-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/publishing-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/publishing-api/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/publishing-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/publishing-api/merges","archive_url":"https://api.github.com/repos/alphagov/publishing-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/publishing-api/downloads","issues_url":"https://api.github.com/repos/alphagov/publishing-api/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/publishing-api/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/publishing-api/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/publishing-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/publishing-api/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/publishing-api/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/publishing-api/deployments","created_at":"2014-12-04T15:15:43Z","updated_at":"2016-12-08T07:53:11Z","pushed_at":"2016-12-15T13:22:28Z","git_url":"git://github.com/alphagov/publishing-api.git","ssh_url":"git@github.com:alphagov/publishing-api.git","clone_url":"https://github.com/alphagov/publishing-api.git","svn_url":"https://github.com/alphagov/publishing-api","homepage":"","size":3254,"stargazers_count":9,"watchers_count":9,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":6,"forks":5,"open_issues":6,"watchers":9,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"571a4c05cc9e4cf6197c947d8455cc499d113678","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":27546098,"name":"publishing-api","full_name":"alphagov/publishing-api","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/publishing-api","description":"Central store for all content on GOV.UK.","fork":false,"url":"https://api.github.com/repos/alphagov/publishing-api","forks_url":"https://api.github.com/repos/alphagov/publishing-api/forks","keys_url":"https://api.github.com/repos/alphagov/publishing-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/publishing-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/publishing-api/teams","hooks_url":"https://api.github.com/repos/alphagov/publishing-api/hooks","issue_events_url":"https://api.github.com/repos/alphagov/publishing-api/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/publishing-api/events","assignees_url":"https://api.github.com/repos/alphagov/publishing-api/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/publishing-api/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/publishing-api/tags","blobs_url":"https://api.github.com/repos/alphagov/publishing-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/publishing-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/publishing-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/publishing-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/publishing-api/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/publishing-api/languages","stargazers_url":"https://api.github.com/repos/alphagov/publishing-api/stargazers","contributors_url":"https://api.github.com/repos/alphagov/publishing-api/contributors","subscribers_url":"https://api.github.com/repos/alphagov/publishing-api/subscribers","subscription_url":"https://api.github.com/repos/alphagov/publishing-api/subscription","commits_url":"https://api.github.com/repos/alphagov/publishing-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/publishing-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/publishing-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/publishing-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/publishing-api/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/publishing-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/publishing-api/merges","archive_url":"https://api.github.com/repos/alphagov/publishing-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/publishing-api/downloads","issues_url":"https://api.github.com/repos/alphagov/publishing-api/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/publishing-api/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/publishing-api/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/publishing-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/publishing-api/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/publishing-api/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/publishing-api/deployments","created_at":"2014-12-04T15:15:43Z","updated_at":"2016-12-08T07:53:11Z","pushed_at":"2016-12-15T13:22:28Z","git_url":"git://github.com/alphagov/publishing-api.git","ssh_url":"git@github.com:alphagov/publishing-api.git","clone_url":"https://github.com/alphagov/publishing-api.git","svn_url":"https://github.com/alphagov/publishing-api","homepage":"","size":3254,"stargazers_count":9,"watchers_count":9,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":6,"forks":5,"open_issues":6,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/622"},"html":{"href":"https://github.com/alphagov/publishing-api/pull/622"},"issue":{"href":"https://api.github.com/repos/alphagov/publishing-api/issues/622"},"comments":{"href":"https://api.github.com/repos/alphagov/publishing-api/issues/622/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/622/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/622/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/publishing-api/statuses/bdfcf34573633f2fe1ee8fc9f065878ad2b84501"}}}}
{"actor":{"display_login":"binaryberry"}}