{"action":"created","comment":{"url":"https://api.github.com/repos/thoughtbot/hound/pulls/comments/31629237","id":31629237,"diff_hunk":"@@ -0,0 +1,60 @@\n+class AssociateViolationsWithFileReviews < ActiveRecord::Migration\n+  class Violation < ActiveRecord::Base\n+    belongs_to :file_review\n+  end\n+  class FileReview < ActiveRecord::Base; end\n+\n+  def up\n+    add_column :file_reviews, :filename, :string, null: false\n+    add_column :violations, :file_review_id, :integer\n+\n+    associate_violations_with_file_reviews\n+\n+    change_column_null :violations, :file_review_id, false\n+    remove_column :violations, :build_id\n+    remove_column :violations, :filename\n+\n+    add_index :violations, :file_review_id\n+    add_foreign_key :violations, :file_reviews, on_delete: :cascade\n+  end\n+\n+  def down\n+    add_column :violations, :build_id, :integer\n+    add_column :violations, :filename, :string\n+\n+    associate_violations_with_builds\n+\n+    change_column_null :violations, :build_id, false\n+    change_column_null :violations, :filename, false\n+    remove_column :violations, :file_review_id\n+    remove_column :file_reviews, :filename, :string, null: false\n+\n+    truncate :file_reviews\n+  end\n+\n+  private\n+\n+  def associate_violations_with_file_reviews\n+    Violation.find_each do |violation|\n+      attributes = {\n+        build_id: violation.build_id,\n+        filename: violation.filename,\n+      }\n+\n+      file_review = FileReview.find_or_create_by!(attributes) do |review|","path":"db/migrate/20150526214750_associate_violations_with_file_reviews.rb","position":44,"original_position":44,"commit_id":"9c5f3edf4231a8043e31d491954e009f37f0fec9","original_commit_id":"57dbea572e5146febd011423a5e559490bad77a0","user":{"login":"salbertson","id":154463,"avatar_url":"https://avatars.githubusercontent.com/u/154463?v=3","gravatar_id":"","url":"https://api.github.com/users/salbertson","html_url":"https://github.com/salbertson","followers_url":"https://api.github.com/users/salbertson/followers","following_url":"https://api.github.com/users/salbertson/following{/other_user}","gists_url":"https://api.github.com/users/salbertson/gists{/gist_id}","starred_url":"https://api.github.com/users/salbertson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/salbertson/subscriptions","organizations_url":"https://api.github.com/users/salbertson/orgs","repos_url":"https://api.github.com/users/salbertson/repos","events_url":"https://api.github.com/users/salbertson/events{/privacy}","received_events_url":"https://api.github.com/users/salbertson/received_events","type":"User","site_admin":false},"body":"Ok, so should we be creating instead of finding or creating?","created_at":"2015-06-03T14:38:41Z","updated_at":"2015-06-03T14:38:41Z","html_url":"https://github.com/thoughtbot/hound/pull/786#discussion_r31629237","pull_request_url":"https://api.github.com/repos/thoughtbot/hound/pulls/786","_links":{"self":{"href":"https://api.github.com/repos/thoughtbot/hound/pulls/comments/31629237"},"html":{"href":"https://github.com/thoughtbot/hound/pull/786#discussion_r31629237"},"pull_request":{"href":"https://api.github.com/repos/thoughtbot/hound/pulls/786"}}},"pull_request":{"url":"https://api.github.com/repos/thoughtbot/hound/pulls/786","id":36262426,"html_url":"https://github.com/thoughtbot/hound/pull/786","diff_url":"https://github.com/thoughtbot/hound/pull/786.diff","patch_url":"https://github.com/thoughtbot/hound/pull/786.patch","issue_url":"https://api.github.com/repos/thoughtbot/hound/issues/786","number":786,"state":"open","locked":false,"title":"Store FileReview records per reviewed file ","user":{"login":"gylaz","id":116327,"avatar_url":"https://avatars.githubusercontent.com/u/116327?v=3","gravatar_id":"","url":"https://api.github.com/users/gylaz","html_url":"https://github.com/gylaz","followers_url":"https://api.github.com/users/gylaz/followers","following_url":"https://api.github.com/users/gylaz/following{/other_user}","gists_url":"https://api.github.com/users/gylaz/gists{/gist_id}","starred_url":"https://api.github.com/users/gylaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gylaz/subscriptions","organizations_url":"https://api.github.com/users/gylaz/orgs","repos_url":"https://api.github.com/users/gylaz/repos","events_url":"https://api.github.com/users/gylaz/events{/privacy}","received_events_url":"https://api.github.com/users/gylaz/received_events","type":"User","site_admin":false},"body":"Violations now belong to FileReview record,\r\nand builds have many file reviews.\r\n\r\nFile reviews have a completed status which can be used for jobs.","created_at":"2015-05-27T01:48:57Z","updated_at":"2015-06-03T14:38:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"42708712d215e04ce3c3c0cddddf43dc1860d784","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/thoughtbot/hound/pulls/786/commits","review_comments_url":"https://api.github.com/repos/thoughtbot/hound/pulls/786/comments","review_comment_url":"https://api.github.com/repos/thoughtbot/hound/pulls/comments{/number}","comments_url":"https://api.github.com/repos/thoughtbot/hound/issues/786/comments","statuses_url":"https://api.github.com/repos/thoughtbot/hound/statuses/9c5f3edf4231a8043e31d491954e009f37f0fec9","head":{"label":"thoughtbot:gl-split-out-file-reviews","ref":"gl-split-out-file-reviews","sha":"9c5f3edf4231a8043e31d491954e009f37f0fec9","user":{"login":"thoughtbot","id":6183,"avatar_url":"https://avatars.githubusercontent.com/u/6183?v=3","gravatar_id":"","url":"https://api.github.com/users/thoughtbot","html_url":"https://github.com/thoughtbot","followers_url":"https://api.github.com/users/thoughtbot/followers","following_url":"https://api.github.com/users/thoughtbot/following{/other_user}","gists_url":"https://api.github.com/users/thoughtbot/gists{/gist_id}","starred_url":"https://api.github.com/users/thoughtbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoughtbot/subscriptions","organizations_url":"https://api.github.com/users/thoughtbot/orgs","repos_url":"https://api.github.com/users/thoughtbot/repos","events_url":"https://api.github.com/users/thoughtbot/events{/privacy}","received_events_url":"https://api.github.com/users/thoughtbot/received_events","type":"Organization","site_admin":false},"repo":{"id":7411076,"name":"hound","full_name":"thoughtbot/hound","owner":{"login":"thoughtbot","id":6183,"avatar_url":"https://avatars.githubusercontent.com/u/6183?v=3","gravatar_id":"","url":"https://api.github.com/users/thoughtbot","html_url":"https://github.com/thoughtbot","followers_url":"https://api.github.com/users/thoughtbot/followers","following_url":"https://api.github.com/users/thoughtbot/following{/other_user}","gists_url":"https://api.github.com/users/thoughtbot/gists{/gist_id}","starred_url":"https://api.github.com/users/thoughtbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoughtbot/subscriptions","organizations_url":"https://api.github.com/users/thoughtbot/orgs","repos_url":"https://api.github.com/users/thoughtbot/repos","events_url":"https://api.github.com/users/thoughtbot/events{/privacy}","received_events_url":"https://api.github.com/users/thoughtbot/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thoughtbot/hound","description":"Review your Ruby, JavaScript, CoffeeScript, and SCSS code for style guide violations with a trusty hound.","fork":false,"url":"https://api.github.com/repos/thoughtbot/hound","forks_url":"https://api.github.com/repos/thoughtbot/hound/forks","keys_url":"https://api.github.com/repos/thoughtbot/hound/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thoughtbot/hound/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thoughtbot/hound/teams","hooks_url":"https://api.github.com/repos/thoughtbot/hound/hooks","issue_events_url":"https://api.github.com/repos/thoughtbot/hound/issues/events{/number}","events_url":"https://api.github.com/repos/thoughtbot/hound/events","assignees_url":"https://api.github.com/repos/thoughtbot/hound/assignees{/user}","branches_url":"https://api.github.com/repos/thoughtbot/hound/branches{/branch}","tags_url":"https://api.github.com/repos/thoughtbot/hound/tags","blobs_url":"https://api.github.com/repos/thoughtbot/hound/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thoughtbot/hound/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thoughtbot/hound/git/refs{/sha}","trees_url":"https://api.github.com/repos/thoughtbot/hound/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thoughtbot/hound/statuses/{sha}","languages_url":"https://api.github.com/repos/thoughtbot/hound/languages","stargazers_url":"https://api.github.com/repos/thoughtbot/hound/stargazers","contributors_url":"https://api.github.com/repos/thoughtbot/hound/contributors","subscribers_url":"https://api.github.com/repos/thoughtbot/hound/subscribers","subscription_url":"https://api.github.com/repos/thoughtbot/hound/subscription","commits_url":"https://api.github.com/repos/thoughtbot/hound/commits{/sha}","git_commits_url":"https://api.github.com/repos/thoughtbot/hound/git/commits{/sha}","comments_url":"https://api.github.com/repos/thoughtbot/hound/comments{/number}","issue_comment_url":"https://api.github.com/repos/thoughtbot/hound/issues/comments{/number}","contents_url":"https://api.github.com/repos/thoughtbot/hound/contents/{+path}","compare_url":"https://api.github.com/repos/thoughtbot/hound/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thoughtbot/hound/merges","archive_url":"https://api.github.com/repos/thoughtbot/hound/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thoughtbot/hound/downloads","issues_url":"https://api.github.com/repos/thoughtbot/hound/issues{/number}","pulls_url":"https://api.github.com/repos/thoughtbot/hound/pulls{/number}","milestones_url":"https://api.github.com/repos/thoughtbot/hound/milestones{/number}","notifications_url":"https://api.github.com/repos/thoughtbot/hound/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thoughtbot/hound/labels{/name}","releases_url":"https://api.github.com/repos/thoughtbot/hound/releases{/id}","created_at":"2013-01-02T18:12:40Z","updated_at":"2015-06-03T14:08:33Z","pushed_at":"2015-06-03T02:03:35Z","git_url":"git://github.com/thoughtbot/hound.git","ssh_url":"git@github.com:thoughtbot/hound.git","clone_url":"https://github.com/thoughtbot/hound.git","svn_url":"https://github.com/thoughtbot/hound","homepage":"https://houndci.com","size":20283,"stargazers_count":919,"watchers_count":919,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":183,"mirror_url":null,"open_issues_count":35,"forks":183,"open_issues":35,"watchers":919,"default_branch":"master"}},"base":{"label":"thoughtbot:master","ref":"master","sha":"17a4ddcd82534455e8d4331b331d0e43754684f2","user":{"login":"thoughtbot","id":6183,"avatar_url":"https://avatars.githubusercontent.com/u/6183?v=3","gravatar_id":"","url":"https://api.github.com/users/thoughtbot","html_url":"https://github.com/thoughtbot","followers_url":"https://api.github.com/users/thoughtbot/followers","following_url":"https://api.github.com/users/thoughtbot/following{/other_user}","gists_url":"https://api.github.com/users/thoughtbot/gists{/gist_id}","starred_url":"https://api.github.com/users/thoughtbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoughtbot/subscriptions","organizations_url":"https://api.github.com/users/thoughtbot/orgs","repos_url":"https://api.github.com/users/thoughtbot/repos","events_url":"https://api.github.com/users/thoughtbot/events{/privacy}","received_events_url":"https://api.github.com/users/thoughtbot/received_events","type":"Organization","site_admin":false},"repo":{"id":7411076,"name":"hound","full_name":"thoughtbot/hound","owner":{"login":"thoughtbot","id":6183,"avatar_url":"https://avatars.githubusercontent.com/u/6183?v=3","gravatar_id":"","url":"https://api.github.com/users/thoughtbot","html_url":"https://github.com/thoughtbot","followers_url":"https://api.github.com/users/thoughtbot/followers","following_url":"https://api.github.com/users/thoughtbot/following{/other_user}","gists_url":"https://api.github.com/users/thoughtbot/gists{/gist_id}","starred_url":"https://api.github.com/users/thoughtbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoughtbot/subscriptions","organizations_url":"https://api.github.com/users/thoughtbot/orgs","repos_url":"https://api.github.com/users/thoughtbot/repos","events_url":"https://api.github.com/users/thoughtbot/events{/privacy}","received_events_url":"https://api.github.com/users/thoughtbot/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thoughtbot/hound","description":"Review your Ruby, JavaScript, CoffeeScript, and SCSS code for style guide violations with a trusty hound.","fork":false,"url":"https://api.github.com/repos/thoughtbot/hound","forks_url":"https://api.github.com/repos/thoughtbot/hound/forks","keys_url":"https://api.github.com/repos/thoughtbot/hound/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thoughtbot/hound/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thoughtbot/hound/teams","hooks_url":"https://api.github.com/repos/thoughtbot/hound/hooks","issue_events_url":"https://api.github.com/repos/thoughtbot/hound/issues/events{/number}","events_url":"https://api.github.com/repos/thoughtbot/hound/events","assignees_url":"https://api.github.com/repos/thoughtbot/hound/assignees{/user}","branches_url":"https://api.github.com/repos/thoughtbot/hound/branches{/branch}","tags_url":"https://api.github.com/repos/thoughtbot/hound/tags","blobs_url":"https://api.github.com/repos/thoughtbot/hound/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thoughtbot/hound/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thoughtbot/hound/git/refs{/sha}","trees_url":"https://api.github.com/repos/thoughtbot/hound/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thoughtbot/hound/statuses/{sha}","languages_url":"https://api.github.com/repos/thoughtbot/hound/languages","stargazers_url":"https://api.github.com/repos/thoughtbot/hound/stargazers","contributors_url":"https://api.github.com/repos/thoughtbot/hound/contributors","subscribers_url":"https://api.github.com/repos/thoughtbot/hound/subscribers","subscription_url":"https://api.github.com/repos/thoughtbot/hound/subscription","commits_url":"https://api.github.com/repos/thoughtbot/hound/commits{/sha}","git_commits_url":"https://api.github.com/repos/thoughtbot/hound/git/commits{/sha}","comments_url":"https://api.github.com/repos/thoughtbot/hound/comments{/number}","issue_comment_url":"https://api.github.com/repos/thoughtbot/hound/issues/comments{/number}","contents_url":"https://api.github.com/repos/thoughtbot/hound/contents/{+path}","compare_url":"https://api.github.com/repos/thoughtbot/hound/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thoughtbot/hound/merges","archive_url":"https://api.github.com/repos/thoughtbot/hound/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thoughtbot/hound/downloads","issues_url":"https://api.github.com/repos/thoughtbot/hound/issues{/number}","pulls_url":"https://api.github.com/repos/thoughtbot/hound/pulls{/number}","milestones_url":"https://api.github.com/repos/thoughtbot/hound/milestones{/number}","notifications_url":"https://api.github.com/repos/thoughtbot/hound/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thoughtbot/hound/labels{/name}","releases_url":"https://api.github.com/repos/thoughtbot/hound/releases{/id}","created_at":"2013-01-02T18:12:40Z","updated_at":"2015-06-03T14:08:33Z","pushed_at":"2015-06-03T02:03:35Z","git_url":"git://github.com/thoughtbot/hound.git","ssh_url":"git@github.com:thoughtbot/hound.git","clone_url":"https://github.com/thoughtbot/hound.git","svn_url":"https://github.com/thoughtbot/hound","homepage":"https://houndci.com","size":20283,"stargazers_count":919,"watchers_count":919,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":183,"mirror_url":null,"open_issues_count":35,"forks":183,"open_issues":35,"watchers":919,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/thoughtbot/hound/pulls/786"},"html":{"href":"https://github.com/thoughtbot/hound/pull/786"},"issue":{"href":"https://api.github.com/repos/thoughtbot/hound/issues/786"},"comments":{"href":"https://api.github.com/repos/thoughtbot/hound/issues/786/comments"},"review_comments":{"href":"https://api.github.com/repos/thoughtbot/hound/pulls/786/comments"},"review_comment":{"href":"https://api.github.com/repos/thoughtbot/hound/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/thoughtbot/hound/pulls/786/commits"},"statuses":{"href":"https://api.github.com/repos/thoughtbot/hound/statuses/9c5f3edf4231a8043e31d491954e009f37f0fec9"}}}}