{"action":"created","comment":{"url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/pulls/comments/36656078","id":36656078,"diff_hunk":"@@ -0,0 +1,97 @@\n+require './lib/wiki'\n+#= Class for generating wikitext for updating assignment details on talk pages\n+class WikiAssignmentOutput\n+  ################\n+  # Entry points #\n+  ################\n+  def self.build_talk_page_update(title,\n+                                  talk_title,\n+                                  title_assignments,\n+                                  course_page)\n+    initial_page_content = Wiki.get_page_content talk_title\n+    # We only want to add assignment tags to non-existant talk pages if the\n+    # article page actually exists. This also servces to make sure that we\n+    # only post to talk pages of mainspace articles, as we assume that pages\n+    # like Talk:Template:Citation or Talk:Wikipedia:Notability do not exist.\n+    if initial_page_content.nil?\n+      return nil if Wiki.get_page_content(title).nil?\n+      initial_page_content = ''\n+    end\n+\n+    # Limit it to live assignments for this article-course\n+    title_assignments = title_assignments.select { |a| !a['deleted'] }\n+\n+    course_assignments_tag = assignments_tag(course_page, title_assignments)\n+    page_content = build_assignment_page_content(course_assignments_tag,\n+                                                 course_page,\n+                                                 initial_page_content)\n+    page_content\n+  end\n+\n+  ###################\n+  # Helper methods #\n+  ###################\n+  def self.assignments_tag(course_page, title_assignments)\n+    return '' if title_assignments.empty?\n+\n+    # Make a list of the assignees, role 0\n+    tag_assigned = build_wikitext_user_list(title_assignments, 0)\n+    # Make a list of the reviwers, role 1\n+    tag_reviewing = build_wikitext_user_list(title_assignments, 1)\n+\n+    # Build new tag\n+    # NOTE: If the format of this tag gets changed, then the dashboard may\n+    # post duplicate tags for the same page, unless we update the way that\n+    # we check for the presense of existging tags to account for both the new\n+    # and old formats.\n+    dashboard_url = Figaro.env.dashboard_url\n+    tag = \"{{#{dashboard_url} assignment | course = #{course_page}\"\n+    tag += \" | assignments = #{tag_assigned}\" unless tag_assigned.blank?\n+    tag += \" | reviewers = #{tag_reviewing}\" unless tag_reviewing.blank?\n+    tag += ' }}'\n+\n+    tag\n+  end\n+\n+  # This method creates updated wikitext for an article talk page, for when\n+  # the set of assigned users for the article for a single course changes.\n+  # The strategy here is to only update the tag for one course at a time, so\n+  # that the user who updates the assignments for a course only introduces data\n+  # for that course. We also want to make as minimal a change as possible, and\n+  # to make sure that we're not disrupting the format of existing content.\n+  def self.build_assignment_page_content(new_tag,\n+                                         course_page,\n+                                         page_content)\n+\n+    dashboard_url = Figaro.env.dashboard_url\n+    # Return if tag already exists on page\n+    unless new_tag.blank?\n+      return nil if page_content.include? new_tag\n+    end\n+\n+    # Check for existing tags and replace\n+    old_tag_ex = \"{{course assignment | course = #{course_page}\"\n+    new_tag_ex = \"{{#{dashboard_url} assignment | course = #{course_page}\"\n+    page_content.gsub!(/#{Regexp.quote(old_tag_ex)}[^\\}]*\\}\\}/, new_tag)\n+    page_content.gsub!(/#{Regexp.quote(new_tag_ex)}[^\\}]*\\}\\}/, new_tag)\n+\n+    # Add new tag at top (if there wasn't an existing tag already)\n+    if !page_content.include?(new_tag) && !new_tag.blank?","path":"lib/wiki_assignment_output.rb","position":79,"original_position":79,"commit_id":"d2ff07f1c681f588e52f1834e86abda9b3dc0597","original_commit_id":"d2ff07f1c681f588e52f1834e86abda9b3dc0597","user":{"login":"ragesoss","id":848483,"avatar_url":"https://avatars.githubusercontent.com/u/848483?v=3","gravatar_id":"","url":"https://api.github.com/users/ragesoss","html_url":"https://github.com/ragesoss","followers_url":"https://api.github.com/users/ragesoss/followers","following_url":"https://api.github.com/users/ragesoss/following{/other_user}","gists_url":"https://api.github.com/users/ragesoss/gists{/gist_id}","starred_url":"https://api.github.com/users/ragesoss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ragesoss/subscriptions","organizations_url":"https://api.github.com/users/ragesoss/orgs","repos_url":"https://api.github.com/users/ragesoss/repos","events_url":"https://api.github.com/users/ragesoss/events{/privacy}","received_events_url":"https://api.github.com/users/ragesoss/received_events","type":"User","site_admin":false},"body":"That was before the gsub, in which we might have replaced an old tag with the new tag. This block is only for the case where we didn't already find somewhere else to put the new tag, so we want to add it to the top section of the page.","created_at":"2015-08-10T17:06:51Z","updated_at":"2015-08-10T17:06:51Z","html_url":"https://github.com/WikiEducationFoundation/WikiEduDashboard/pull/281#discussion_r36656078","pull_request_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/pulls/281","_links":{"self":{"href":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/pulls/comments/36656078"},"html":{"href":"https://github.com/WikiEducationFoundation/WikiEduDashboard/pull/281#discussion_r36656078"},"pull_request":{"href":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/pulls/281"}}},"pull_request":{"url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/pulls/281","id":42036102,"html_url":"https://github.com/WikiEducationFoundation/WikiEduDashboard/pull/281","diff_url":"https://github.com/WikiEducationFoundation/WikiEduDashboard/pull/281.diff","patch_url":"https://github.com/WikiEducationFoundation/WikiEduDashboard/pull/281.patch","issue_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/issues/281","number":281,"state":"open","locked":false,"title":"Wiki edits refactor","user":{"login":"ragesoss","id":848483,"avatar_url":"https://avatars.githubusercontent.com/u/848483?v=3","gravatar_id":"","url":"https://api.github.com/users/ragesoss","html_url":"https://github.com/ragesoss","followers_url":"https://api.github.com/users/ragesoss/followers","following_url":"https://api.github.com/users/ragesoss/following{/other_user}","gists_url":"https://api.github.com/users/ragesoss/gists{/gist_id}","starred_url":"https://api.github.com/users/ragesoss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ragesoss/subscriptions","organizations_url":"https://api.github.com/users/ragesoss/orgs","repos_url":"https://api.github.com/users/ragesoss/repos","events_url":"https://api.github.com/users/ragesoss/events{/privacy}","received_events_url":"https://api.github.com/users/ragesoss/received_events","type":"User","site_admin":false},"body":"@thenickcox: I'd love to get a code review for this. (I'll probably be showing up at the WINTR office today, FYI.)","created_at":"2015-08-10T16:01:08Z","updated_at":"2015-08-10T17:06:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b728bfdb4dc38e72e3bd5bf399bbb3129830fdd0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/pulls/281/commits","review_comments_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/pulls/281/comments","review_comment_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/pulls/comments{/number}","comments_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/issues/281/comments","statuses_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/statuses/d2ff07f1c681f588e52f1834e86abda9b3dc0597","head":{"label":"WikiEducationFoundation:WikiEdits-refactor","ref":"WikiEdits-refactor","sha":"d2ff07f1c681f588e52f1834e86abda9b3dc0597","user":{"login":"WikiEducationFoundation","id":9489865,"avatar_url":"https://avatars.githubusercontent.com/u/9489865?v=3","gravatar_id":"","url":"https://api.github.com/users/WikiEducationFoundation","html_url":"https://github.com/WikiEducationFoundation","followers_url":"https://api.github.com/users/WikiEducationFoundation/followers","following_url":"https://api.github.com/users/WikiEducationFoundation/following{/other_user}","gists_url":"https://api.github.com/users/WikiEducationFoundation/gists{/gist_id}","starred_url":"https://api.github.com/users/WikiEducationFoundation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WikiEducationFoundation/subscriptions","organizations_url":"https://api.github.com/users/WikiEducationFoundation/orgs","repos_url":"https://api.github.com/users/WikiEducationFoundation/repos","events_url":"https://api.github.com/users/WikiEducationFoundation/events{/privacy}","received_events_url":"https://api.github.com/users/WikiEducationFoundation/received_events","type":"Organization","site_admin":false},"repo":{"id":27940263,"name":"WikiEduDashboard","full_name":"WikiEducationFoundation/WikiEduDashboard","owner":{"login":"WikiEducationFoundation","id":9489865,"avatar_url":"https://avatars.githubusercontent.com/u/9489865?v=3","gravatar_id":"","url":"https://api.github.com/users/WikiEducationFoundation","html_url":"https://github.com/WikiEducationFoundation","followers_url":"https://api.github.com/users/WikiEducationFoundation/followers","following_url":"https://api.github.com/users/WikiEducationFoundation/following{/other_user}","gists_url":"https://api.github.com/users/WikiEducationFoundation/gists{/gist_id}","starred_url":"https://api.github.com/users/WikiEducationFoundation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WikiEducationFoundation/subscriptions","organizations_url":"https://api.github.com/users/WikiEducationFoundation/orgs","repos_url":"https://api.github.com/users/WikiEducationFoundation/repos","events_url":"https://api.github.com/users/WikiEducationFoundation/events{/privacy}","received_events_url":"https://api.github.com/users/WikiEducationFoundation/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WikiEducationFoundation/WikiEduDashboard","description":"Dashboard application facilitating Wikiedu-powered courses","fork":false,"url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard","forks_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/forks","keys_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/teams","hooks_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/hooks","issue_events_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/issues/events{/number}","events_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/events","assignees_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/assignees{/user}","branches_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/branches{/branch}","tags_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/tags","blobs_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/git/refs{/sha}","trees_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/statuses/{sha}","languages_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/languages","stargazers_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/stargazers","contributors_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/contributors","subscribers_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/subscribers","subscription_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/subscription","commits_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/commits{/sha}","git_commits_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/git/commits{/sha}","comments_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/comments{/number}","issue_comment_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/issues/comments{/number}","contents_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/contents/{+path}","compare_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/merges","archive_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/downloads","issues_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/issues{/number}","pulls_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/pulls{/number}","milestones_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/milestones{/number}","notifications_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/labels{/name}","releases_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/releases{/id}","created_at":"2014-12-12T22:13:19Z","updated_at":"2015-07-31T20:16:22Z","pushed_at":"2015-08-10T16:18:35Z","git_url":"git://github.com/WikiEducationFoundation/WikiEduDashboard.git","ssh_url":"git@github.com:WikiEducationFoundation/WikiEduDashboard.git","clone_url":"https://github.com/WikiEducationFoundation/WikiEduDashboard.git","svn_url":"https://github.com/WikiEducationFoundation/WikiEduDashboard","homepage":null,"size":49604,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":46,"forks":7,"open_issues":46,"watchers":4,"default_branch":"master"}},"base":{"label":"WikiEducationFoundation:master","ref":"master","sha":"6889840876be83742eda6f15f2e251ff736ccb27","user":{"login":"WikiEducationFoundation","id":9489865,"avatar_url":"https://avatars.githubusercontent.com/u/9489865?v=3","gravatar_id":"","url":"https://api.github.com/users/WikiEducationFoundation","html_url":"https://github.com/WikiEducationFoundation","followers_url":"https://api.github.com/users/WikiEducationFoundation/followers","following_url":"https://api.github.com/users/WikiEducationFoundation/following{/other_user}","gists_url":"https://api.github.com/users/WikiEducationFoundation/gists{/gist_id}","starred_url":"https://api.github.com/users/WikiEducationFoundation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WikiEducationFoundation/subscriptions","organizations_url":"https://api.github.com/users/WikiEducationFoundation/orgs","repos_url":"https://api.github.com/users/WikiEducationFoundation/repos","events_url":"https://api.github.com/users/WikiEducationFoundation/events{/privacy}","received_events_url":"https://api.github.com/users/WikiEducationFoundation/received_events","type":"Organization","site_admin":false},"repo":{"id":27940263,"name":"WikiEduDashboard","full_name":"WikiEducationFoundation/WikiEduDashboard","owner":{"login":"WikiEducationFoundation","id":9489865,"avatar_url":"https://avatars.githubusercontent.com/u/9489865?v=3","gravatar_id":"","url":"https://api.github.com/users/WikiEducationFoundation","html_url":"https://github.com/WikiEducationFoundation","followers_url":"https://api.github.com/users/WikiEducationFoundation/followers","following_url":"https://api.github.com/users/WikiEducationFoundation/following{/other_user}","gists_url":"https://api.github.com/users/WikiEducationFoundation/gists{/gist_id}","starred_url":"https://api.github.com/users/WikiEducationFoundation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WikiEducationFoundation/subscriptions","organizations_url":"https://api.github.com/users/WikiEducationFoundation/orgs","repos_url":"https://api.github.com/users/WikiEducationFoundation/repos","events_url":"https://api.github.com/users/WikiEducationFoundation/events{/privacy}","received_events_url":"https://api.github.com/users/WikiEducationFoundation/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WikiEducationFoundation/WikiEduDashboard","description":"Dashboard application facilitating Wikiedu-powered courses","fork":false,"url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard","forks_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/forks","keys_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/teams","hooks_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/hooks","issue_events_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/issues/events{/number}","events_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/events","assignees_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/assignees{/user}","branches_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/branches{/branch}","tags_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/tags","blobs_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/git/refs{/sha}","trees_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/statuses/{sha}","languages_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/languages","stargazers_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/stargazers","contributors_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/contributors","subscribers_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/subscribers","subscription_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/subscription","commits_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/commits{/sha}","git_commits_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/git/commits{/sha}","comments_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/comments{/number}","issue_comment_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/issues/comments{/number}","contents_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/contents/{+path}","compare_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/merges","archive_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/downloads","issues_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/issues{/number}","pulls_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/pulls{/number}","milestones_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/milestones{/number}","notifications_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/labels{/name}","releases_url":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/releases{/id}","created_at":"2014-12-12T22:13:19Z","updated_at":"2015-07-31T20:16:22Z","pushed_at":"2015-08-10T16:18:35Z","git_url":"git://github.com/WikiEducationFoundation/WikiEduDashboard.git","ssh_url":"git@github.com:WikiEducationFoundation/WikiEduDashboard.git","clone_url":"https://github.com/WikiEducationFoundation/WikiEduDashboard.git","svn_url":"https://github.com/WikiEducationFoundation/WikiEduDashboard","homepage":null,"size":49604,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":46,"forks":7,"open_issues":46,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/pulls/281"},"html":{"href":"https://github.com/WikiEducationFoundation/WikiEduDashboard/pull/281"},"issue":{"href":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/issues/281"},"comments":{"href":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/issues/281/comments"},"review_comments":{"href":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/pulls/281/comments"},"review_comment":{"href":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/pulls/281/commits"},"statuses":{"href":"https://api.github.com/repos/WikiEducationFoundation/WikiEduDashboard/statuses/d2ff07f1c681f588e52f1834e86abda9b3dc0597"}}}}