{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/whitehall/pulls/comments/78385424","id":78385424,"diff_hunk":"@@ -151,12 +144,63 @@ def related_mainstream_content_valid?\n     end\n   end\n \n+\n   def additional_related_mainstream_content_valid?\n     if additional_related_mainstream_content_url.present? && additional_related_mainstream_content_title.blank?\n       errors.add(:additional_related_mainstream_content_title, \"cannot be blank if an additional related URL is given\")\n     end\n   end\n \n+  def related_mainstream_found\n+    return unless related_mainstream_requested?\n+    fetch_related_mainstream_content_ids\n+    add_errors_for_missing_related_mainstream\n+    add_errors_for_missing_additional_related_mainstream\n+  end\n+\n+  def add_errors_for_missing_related_mainstream\n+    if @content_ids.count >= 1\n+      errors.add(:related_mainstream_content_url, \"This mainstream content could not be found\") if @content_ids[0].nil?\n+    end\n+  end\n+\n+  def add_errors_for_missing_additional_related_mainstream\n+    if @content_ids.count > 1\n+      errors.add(:additional_related_mainstream_content_url, \"This mainstream content could not be found\") if @content_ids[1].nil?\n+    end\n+  end\n+\n+  def fetch_related_mainstream_content_ids\n+    base_paths = [related_mainstream_base_path, additional_related_mainstream_base_path].compact\n+    if need_to_fetch_related_mainstream?(base_paths)\n+      @content_ids ||= []\n+      lookup_content_ids(base_paths)\n+    else\n+      @content_ids ||= []\n+    end\n+  end\n+\n+  def need_to_fetch_related_mainstream?(base_paths)\n+    base_paths.any? && @content_ids.nil?\n+  end\n+\n+  def lookup_content_ids(base_paths)\n+    base_paths.each do |base_path|\n+      content_id = Whitehall.publishing_api_v2_client.lookup_content_id(base_path: base_path)\n+      @content_ids << content_id\n+    end\n+  end\n+\n+  def related_mainstream_requested?\n+    related_mainstream_content_url.present? || additional_related_mainstream_content_url.present?\n+  end\n+\n+  def persist_content_ids\n+    return if @content_ids.nil? || @content_ids.compact.empty?\n+    RelatedMainstream.find_or_create_by!(edition_id: self.id, content_id: @content_ids[0])","path":"app/models/detailed_guide.rb","position":null,"original_position":94,"commit_id":"46c747f9e7daea94189544bbb8a94b355a7e6d36","original_commit_id":"b9c1cdf64439f05af0e60b541ed2eba0a5b0b084","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":"Amended in 46c747","created_at":"2016-09-12T14:39:31Z","updated_at":"2016-09-12T14:39:31Z","html_url":"https://github.com/alphagov/whitehall/pull/2747#discussion_r78385424","pull_request_url":"https://api.github.com/repos/alphagov/whitehall/pulls/2747","_links":{"self":{"href":"https://api.github.com/repos/alphagov/whitehall/pulls/comments/78385424"},"html":{"href":"https://github.com/alphagov/whitehall/pull/2747#discussion_r78385424"},"pull_request":{"href":"https://api.github.com/repos/alphagov/whitehall/pulls/2747"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/whitehall/pulls/2747","id":84623832,"html_url":"https://github.com/alphagov/whitehall/pull/2747","diff_url":"https://github.com/alphagov/whitehall/pull/2747.diff","patch_url":"https://github.com/alphagov/whitehall/pull/2747.patch","issue_url":"https://api.github.com/repos/alphagov/whitehall/issues/2747","number":2747,"state":"open","locked":false,"title":"[WIP] Improve related mainstream linking","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":"Work in progress, opening for comments - do not merge s'il vous plait :-)","created_at":"2016-09-09T09:55:38Z","updated_at":"2016-09-12T14:39:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e779f7aecb365a546039e3229dae46f130fb49c0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/whitehall/pulls/2747/commits","review_comments_url":"https://api.github.com/repos/alphagov/whitehall/pulls/2747/comments","review_comment_url":"https://api.github.com/repos/alphagov/whitehall/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/whitehall/issues/2747/comments","statuses_url":"https://api.github.com/repos/alphagov/whitehall/statuses/46c747f9e7daea94189544bbb8a94b355a7e6d36","head":{"label":"alphagov:improve-related-mainstream-linking","ref":"improve-related-mainstream-linking","sha":"46c747f9e7daea94189544bbb8a94b355a7e6d36","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":2416064,"name":"whitehall","full_name":"alphagov/whitehall","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/whitehall","description":"Rails application that serves most pages on www.gov.uk/government","fork":false,"url":"https://api.github.com/repos/alphagov/whitehall","forks_url":"https://api.github.com/repos/alphagov/whitehall/forks","keys_url":"https://api.github.com/repos/alphagov/whitehall/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/whitehall/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/whitehall/teams","hooks_url":"https://api.github.com/repos/alphagov/whitehall/hooks","issue_events_url":"https://api.github.com/repos/alphagov/whitehall/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/whitehall/events","assignees_url":"https://api.github.com/repos/alphagov/whitehall/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/whitehall/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/whitehall/tags","blobs_url":"https://api.github.com/repos/alphagov/whitehall/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/whitehall/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/whitehall/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/whitehall/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/whitehall/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/whitehall/languages","stargazers_url":"https://api.github.com/repos/alphagov/whitehall/stargazers","contributors_url":"https://api.github.com/repos/alphagov/whitehall/contributors","subscribers_url":"https://api.github.com/repos/alphagov/whitehall/subscribers","subscription_url":"https://api.github.com/repos/alphagov/whitehall/subscription","commits_url":"https://api.github.com/repos/alphagov/whitehall/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/whitehall/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/whitehall/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/whitehall/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/whitehall/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/whitehall/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/whitehall/merges","archive_url":"https://api.github.com/repos/alphagov/whitehall/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/whitehall/downloads","issues_url":"https://api.github.com/repos/alphagov/whitehall/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/whitehall/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/whitehall/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/whitehall/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/whitehall/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/whitehall/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/whitehall/deployments","created_at":"2011-09-19T15:10:49Z","updated_at":"2016-09-09T16:50:06Z","pushed_at":"2016-09-12T14:38:12Z","git_url":"git://github.com/alphagov/whitehall.git","ssh_url":"git@github.com:alphagov/whitehall.git","clone_url":"https://github.com/alphagov/whitehall.git","svn_url":"https://github.com/alphagov/whitehall","homepage":"","size":246961,"stargazers_count":361,"watchers_count":361,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":143,"mirror_url":null,"open_issues_count":6,"forks":143,"open_issues":6,"watchers":361,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"a07fa55c8677884e48abc7b0422cf45a1e237150","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":2416064,"name":"whitehall","full_name":"alphagov/whitehall","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/whitehall","description":"Rails application that serves most pages on www.gov.uk/government","fork":false,"url":"https://api.github.com/repos/alphagov/whitehall","forks_url":"https://api.github.com/repos/alphagov/whitehall/forks","keys_url":"https://api.github.com/repos/alphagov/whitehall/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/whitehall/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/whitehall/teams","hooks_url":"https://api.github.com/repos/alphagov/whitehall/hooks","issue_events_url":"https://api.github.com/repos/alphagov/whitehall/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/whitehall/events","assignees_url":"https://api.github.com/repos/alphagov/whitehall/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/whitehall/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/whitehall/tags","blobs_url":"https://api.github.com/repos/alphagov/whitehall/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/whitehall/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/whitehall/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/whitehall/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/whitehall/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/whitehall/languages","stargazers_url":"https://api.github.com/repos/alphagov/whitehall/stargazers","contributors_url":"https://api.github.com/repos/alphagov/whitehall/contributors","subscribers_url":"https://api.github.com/repos/alphagov/whitehall/subscribers","subscription_url":"https://api.github.com/repos/alphagov/whitehall/subscription","commits_url":"https://api.github.com/repos/alphagov/whitehall/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/whitehall/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/whitehall/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/whitehall/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/whitehall/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/whitehall/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/whitehall/merges","archive_url":"https://api.github.com/repos/alphagov/whitehall/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/whitehall/downloads","issues_url":"https://api.github.com/repos/alphagov/whitehall/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/whitehall/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/whitehall/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/whitehall/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/whitehall/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/whitehall/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/whitehall/deployments","created_at":"2011-09-19T15:10:49Z","updated_at":"2016-09-09T16:50:06Z","pushed_at":"2016-09-12T14:38:12Z","git_url":"git://github.com/alphagov/whitehall.git","ssh_url":"git@github.com:alphagov/whitehall.git","clone_url":"https://github.com/alphagov/whitehall.git","svn_url":"https://github.com/alphagov/whitehall","homepage":"","size":246961,"stargazers_count":361,"watchers_count":361,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":143,"mirror_url":null,"open_issues_count":6,"forks":143,"open_issues":6,"watchers":361,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/whitehall/pulls/2747"},"html":{"href":"https://github.com/alphagov/whitehall/pull/2747"},"issue":{"href":"https://api.github.com/repos/alphagov/whitehall/issues/2747"},"comments":{"href":"https://api.github.com/repos/alphagov/whitehall/issues/2747/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/whitehall/pulls/2747/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/whitehall/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/whitehall/pulls/2747/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/whitehall/statuses/46c747f9e7daea94189544bbb8a94b355a7e6d36"}}}}
{"actor":{"display_login":"binaryberry"}}