{"action":"created","comment":{"url":"https://api.github.com/repos/netguru/access/pulls/comments/51257655","id":51257655,"diff_hunk":"@@ -0,0 +1,87 @@\n+module HockeyAppIntegration\n+  module Actions\n+    class Sync\n+      attr_reader :hockeyapp_api, :diff\n+      def initialize(hockeyapp_api, diff)\n+        @hockeyapp_api = hockeyapp_api\n+        @diff = diff\n+      end\n+\n+      def now!\n+        sync_add_teams\n+        sync_remove_teams\n+        sync_add_users\n+        sync_remove_users\n+      end\n+\n+      private\n+\n+      def all_teams\n+        @all_teams ||= hockeyapp_api.list_teams['teams']\n+      end\n+\n+      def find_team_id(team_name)\n+        all_teams.each do |team|\n+          return team['id'] if team['name'] == team_name\n+        end\n+      end\n+\n+      def all_app_users(app)\n+        hockeyapp_api.list_app_users(app.public_identifier)['app_users']\n+      end\n+\n+      def find_user_id(app, user_email)\n+        all_app_users(app).each do |user|\n+          return user['id'] if user['email'] == user_email\n+        end\n+      end\n+\n+      def sync_add_teams\n+        diff[:add_teams].each do |app, teams|\n+          each_team(teams) do |team_id|\n+            hockeyapp_api.add_team_to_app(app.public_identifier, team_id)\n+          end\n+        end\n+      end\n+\n+      def sync_remove_teams\n+        diff[:remove_teams].each do |app, teams|\n+          each_team(teams) do |team_id|\n+            hockeyapp_api.remove_team_from_app(app.public_identifier, team_id)\n+          end\n+        end\n+      end\n+\n+      def sync_add_users\n+        diff[:add_users].each do |app, users|\n+          each_user(users, app) do |role_id, user_email, user_id|","path":"app/models/hockey_app_integration/actions/sync.rb","position":57,"original_position":57,"commit_id":"8a7c13b3a58f5764d272a6bea71711c35136fae3","original_commit_id":"8a7c13b3a58f5764d272a6bea71711c35136fae3","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Unused block argument - `user_id`. If it's necessary, use `_` or `_user_id` as an argument name to indicate that it won't be used.","created_at":"2016-01-29T12:58:41Z","updated_at":"2016-01-29T12:58:41Z","html_url":"https://github.com/netguru/access/pull/40#discussion_r51257655","pull_request_url":"https://api.github.com/repos/netguru/access/pulls/40","_links":{"self":{"href":"https://api.github.com/repos/netguru/access/pulls/comments/51257655"},"html":{"href":"https://github.com/netguru/access/pull/40#discussion_r51257655"},"pull_request":{"href":"https://api.github.com/repos/netguru/access/pulls/40"}}},"pull_request":{"url":"https://api.github.com/repos/netguru/access/pulls/40","id":57629042,"html_url":"https://github.com/netguru/access/pull/40","diff_url":"https://github.com/netguru/access/pull/40.diff","patch_url":"https://github.com/netguru/access/pull/40.patch","issue_url":"https://api.github.com/repos/netguru/access/issues/40","number":40,"state":"open","locked":false,"title":"Feature/hockeyapp sync","user":{"login":"siepet","id":2729370,"avatar_url":"https://avatars.githubusercontent.com/u/2729370?v=3","gravatar_id":"","url":"https://api.github.com/users/siepet","html_url":"https://github.com/siepet","followers_url":"https://api.github.com/users/siepet/followers","following_url":"https://api.github.com/users/siepet/following{/other_user}","gists_url":"https://api.github.com/users/siepet/gists{/gist_id}","starred_url":"https://api.github.com/users/siepet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/siepet/subscriptions","organizations_url":"https://api.github.com/users/siepet/orgs","repos_url":"https://api.github.com/users/siepet/repos","events_url":"https://api.github.com/users/siepet/events{/privacy}","received_events_url":"https://api.github.com/users/siepet/received_events","type":"User","site_admin":false},"body":"Makes it possible to sync changes based on a diff.","created_at":"2016-01-29T10:18:37Z","updated_at":"2016-01-29T12:58:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aca0e73e045f516d6ba284fdbe6be60d57b5c7c0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/netguru/access/pulls/40/commits","review_comments_url":"https://api.github.com/repos/netguru/access/pulls/40/comments","review_comment_url":"https://api.github.com/repos/netguru/access/pulls/comments{/number}","comments_url":"https://api.github.com/repos/netguru/access/issues/40/comments","statuses_url":"https://api.github.com/repos/netguru/access/statuses/8a7c13b3a58f5764d272a6bea71711c35136fae3","head":{"label":"netguru:feature/hockeyapp-sync","ref":"feature/hockeyapp-sync","sha":"8a7c13b3a58f5764d272a6bea71711c35136fae3","user":{"login":"netguru","id":1146,"avatar_url":"https://avatars.githubusercontent.com/u/1146?v=3","gravatar_id":"","url":"https://api.github.com/users/netguru","html_url":"https://github.com/netguru","followers_url":"https://api.github.com/users/netguru/followers","following_url":"https://api.github.com/users/netguru/following{/other_user}","gists_url":"https://api.github.com/users/netguru/gists{/gist_id}","starred_url":"https://api.github.com/users/netguru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netguru/subscriptions","organizations_url":"https://api.github.com/users/netguru/orgs","repos_url":"https://api.github.com/users/netguru/repos","events_url":"https://api.github.com/users/netguru/events{/privacy}","received_events_url":"https://api.github.com/users/netguru/received_events","type":"Organization","site_admin":false},"repo":{"id":24055977,"name":"access","full_name":"netguru/access","owner":{"login":"netguru","id":1146,"avatar_url":"https://avatars.githubusercontent.com/u/1146?v=3","gravatar_id":"","url":"https://api.github.com/users/netguru","html_url":"https://github.com/netguru","followers_url":"https://api.github.com/users/netguru/followers","following_url":"https://api.github.com/users/netguru/following{/other_user}","gists_url":"https://api.github.com/users/netguru/gists{/gist_id}","starred_url":"https://api.github.com/users/netguru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netguru/subscriptions","organizations_url":"https://api.github.com/users/netguru/orgs","repos_url":"https://api.github.com/users/netguru/repos","events_url":"https://api.github.com/users/netguru/events{/privacy}","received_events_url":"https://api.github.com/users/netguru/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/netguru/access","description":"Push style access app for github and google apps","fork":false,"url":"https://api.github.com/repos/netguru/access","forks_url":"https://api.github.com/repos/netguru/access/forks","keys_url":"https://api.github.com/repos/netguru/access/keys{/key_id}","collaborators_url":"https://api.github.com/repos/netguru/access/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/netguru/access/teams","hooks_url":"https://api.github.com/repos/netguru/access/hooks","issue_events_url":"https://api.github.com/repos/netguru/access/issues/events{/number}","events_url":"https://api.github.com/repos/netguru/access/events","assignees_url":"https://api.github.com/repos/netguru/access/assignees{/user}","branches_url":"https://api.github.com/repos/netguru/access/branches{/branch}","tags_url":"https://api.github.com/repos/netguru/access/tags","blobs_url":"https://api.github.com/repos/netguru/access/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/netguru/access/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/netguru/access/git/refs{/sha}","trees_url":"https://api.github.com/repos/netguru/access/git/trees{/sha}","statuses_url":"https://api.github.com/repos/netguru/access/statuses/{sha}","languages_url":"https://api.github.com/repos/netguru/access/languages","stargazers_url":"https://api.github.com/repos/netguru/access/stargazers","contributors_url":"https://api.github.com/repos/netguru/access/contributors","subscribers_url":"https://api.github.com/repos/netguru/access/subscribers","subscription_url":"https://api.github.com/repos/netguru/access/subscription","commits_url":"https://api.github.com/repos/netguru/access/commits{/sha}","git_commits_url":"https://api.github.com/repos/netguru/access/git/commits{/sha}","comments_url":"https://api.github.com/repos/netguru/access/comments{/number}","issue_comment_url":"https://api.github.com/repos/netguru/access/issues/comments{/number}","contents_url":"https://api.github.com/repos/netguru/access/contents/{+path}","compare_url":"https://api.github.com/repos/netguru/access/compare/{base}...{head}","merges_url":"https://api.github.com/repos/netguru/access/merges","archive_url":"https://api.github.com/repos/netguru/access/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/netguru/access/downloads","issues_url":"https://api.github.com/repos/netguru/access/issues{/number}","pulls_url":"https://api.github.com/repos/netguru/access/pulls{/number}","milestones_url":"https://api.github.com/repos/netguru/access/milestones{/number}","notifications_url":"https://api.github.com/repos/netguru/access/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/netguru/access/labels{/name}","releases_url":"https://api.github.com/repos/netguru/access/releases{/id}","deployments_url":"https://api.github.com/repos/netguru/access/deployments","created_at":"2014-09-15T12:43:28Z","updated_at":"2016-01-11T10:17:56Z","pushed_at":"2016-01-29T12:58:36Z","git_url":"git://github.com/netguru/access.git","ssh_url":"git@github.com:netguru/access.git","clone_url":"https://github.com/netguru/access.git","svn_url":"https://github.com/netguru/access","homepage":"https://netguru.co/opensource","size":37723,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":1,"forks":5,"open_issues":1,"watchers":3,"default_branch":"master"}},"base":{"label":"netguru:master","ref":"master","sha":"d754db58bf0b87192cf81e1ccd65aa4a137ff201","user":{"login":"netguru","id":1146,"avatar_url":"https://avatars.githubusercontent.com/u/1146?v=3","gravatar_id":"","url":"https://api.github.com/users/netguru","html_url":"https://github.com/netguru","followers_url":"https://api.github.com/users/netguru/followers","following_url":"https://api.github.com/users/netguru/following{/other_user}","gists_url":"https://api.github.com/users/netguru/gists{/gist_id}","starred_url":"https://api.github.com/users/netguru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netguru/subscriptions","organizations_url":"https://api.github.com/users/netguru/orgs","repos_url":"https://api.github.com/users/netguru/repos","events_url":"https://api.github.com/users/netguru/events{/privacy}","received_events_url":"https://api.github.com/users/netguru/received_events","type":"Organization","site_admin":false},"repo":{"id":24055977,"name":"access","full_name":"netguru/access","owner":{"login":"netguru","id":1146,"avatar_url":"https://avatars.githubusercontent.com/u/1146?v=3","gravatar_id":"","url":"https://api.github.com/users/netguru","html_url":"https://github.com/netguru","followers_url":"https://api.github.com/users/netguru/followers","following_url":"https://api.github.com/users/netguru/following{/other_user}","gists_url":"https://api.github.com/users/netguru/gists{/gist_id}","starred_url":"https://api.github.com/users/netguru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/netguru/subscriptions","organizations_url":"https://api.github.com/users/netguru/orgs","repos_url":"https://api.github.com/users/netguru/repos","events_url":"https://api.github.com/users/netguru/events{/privacy}","received_events_url":"https://api.github.com/users/netguru/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/netguru/access","description":"Push style access app for github and google apps","fork":false,"url":"https://api.github.com/repos/netguru/access","forks_url":"https://api.github.com/repos/netguru/access/forks","keys_url":"https://api.github.com/repos/netguru/access/keys{/key_id}","collaborators_url":"https://api.github.com/repos/netguru/access/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/netguru/access/teams","hooks_url":"https://api.github.com/repos/netguru/access/hooks","issue_events_url":"https://api.github.com/repos/netguru/access/issues/events{/number}","events_url":"https://api.github.com/repos/netguru/access/events","assignees_url":"https://api.github.com/repos/netguru/access/assignees{/user}","branches_url":"https://api.github.com/repos/netguru/access/branches{/branch}","tags_url":"https://api.github.com/repos/netguru/access/tags","blobs_url":"https://api.github.com/repos/netguru/access/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/netguru/access/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/netguru/access/git/refs{/sha}","trees_url":"https://api.github.com/repos/netguru/access/git/trees{/sha}","statuses_url":"https://api.github.com/repos/netguru/access/statuses/{sha}","languages_url":"https://api.github.com/repos/netguru/access/languages","stargazers_url":"https://api.github.com/repos/netguru/access/stargazers","contributors_url":"https://api.github.com/repos/netguru/access/contributors","subscribers_url":"https://api.github.com/repos/netguru/access/subscribers","subscription_url":"https://api.github.com/repos/netguru/access/subscription","commits_url":"https://api.github.com/repos/netguru/access/commits{/sha}","git_commits_url":"https://api.github.com/repos/netguru/access/git/commits{/sha}","comments_url":"https://api.github.com/repos/netguru/access/comments{/number}","issue_comment_url":"https://api.github.com/repos/netguru/access/issues/comments{/number}","contents_url":"https://api.github.com/repos/netguru/access/contents/{+path}","compare_url":"https://api.github.com/repos/netguru/access/compare/{base}...{head}","merges_url":"https://api.github.com/repos/netguru/access/merges","archive_url":"https://api.github.com/repos/netguru/access/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/netguru/access/downloads","issues_url":"https://api.github.com/repos/netguru/access/issues{/number}","pulls_url":"https://api.github.com/repos/netguru/access/pulls{/number}","milestones_url":"https://api.github.com/repos/netguru/access/milestones{/number}","notifications_url":"https://api.github.com/repos/netguru/access/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/netguru/access/labels{/name}","releases_url":"https://api.github.com/repos/netguru/access/releases{/id}","deployments_url":"https://api.github.com/repos/netguru/access/deployments","created_at":"2014-09-15T12:43:28Z","updated_at":"2016-01-11T10:17:56Z","pushed_at":"2016-01-29T12:58:36Z","git_url":"git://github.com/netguru/access.git","ssh_url":"git@github.com:netguru/access.git","clone_url":"https://github.com/netguru/access.git","svn_url":"https://github.com/netguru/access","homepage":"https://netguru.co/opensource","size":37723,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":1,"forks":5,"open_issues":1,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/netguru/access/pulls/40"},"html":{"href":"https://github.com/netguru/access/pull/40"},"issue":{"href":"https://api.github.com/repos/netguru/access/issues/40"},"comments":{"href":"https://api.github.com/repos/netguru/access/issues/40/comments"},"review_comments":{"href":"https://api.github.com/repos/netguru/access/pulls/40/comments"},"review_comment":{"href":"https://api.github.com/repos/netguru/access/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/netguru/access/pulls/40/commits"},"statuses":{"href":"https://api.github.com/repos/netguru/access/statuses/8a7c13b3a58f5764d272a6bea71711c35136fae3"}}}}