{"action":"created","comment":{"url":"https://api.github.com/repos/mikestephens/circle_reaper/pulls/comments/70902573","id":70902573,"diff_hunk":"@@ -1,21 +1,33 @@\n-require \"sidekiq\"\n-\n module CircleReaper\n   class CircleWorker\n+    include Sidekiq::Worker\n+\n     def perform(payload)\n       owner  = payload.fetch(:repository).fetch(:owner).fetch(:name)\n       repo   = payload.fetch(:repository).fetch(:name)\n-      branch = payload.fetch(:ref).split('/').last\n+      branch = payload.fetch(:ref).split(\"/\").last\n+\n+      return if branch == \"master\"\n \n-      unless branch == \"master\"\n-        builds = CircleCi::Project.recent_builds_branch(owner, repo, branch).body.select{|build| build[\"stop_time\"].nil? && build[\"why\"] == \"github\"}\n-        if builds.count > 1\n-          builds.drop(1).each do |build|\n-            puts build[\"build_num\"]\n-            CircleCi::Build.cancel owner, repo, build[\"build_num\"]\n-          end\n+      if builds.count > 1\n+        builds.drop(1).each do |build|\n+          CircleCi::Build.cancel(owner, repo, build[\"build_num\"])\n         end\n       end\n     end\n+\n+    def builds\n+      @builds ||= find_builds\n+    end\n+\n+    def find_builds\n+      recent_builds_branch.select do |build|","path":"lib/circle_reaper/circle_worker.rb","position":34,"original_position":34,"commit_id":"774099b04185f8be197407e6ecc86513781aa06a","original_commit_id":"774099b04185f8be197407e6ecc86513781aa06a","user":{"login":"mikestephens","id":1581475,"avatar_url":"https://avatars.githubusercontent.com/u/1581475?v=3","gravatar_id":"","url":"https://api.github.com/users/mikestephens","html_url":"https://github.com/mikestephens","followers_url":"https://api.github.com/users/mikestephens/followers","following_url":"https://api.github.com/users/mikestephens/following{/other_user}","gists_url":"https://api.github.com/users/mikestephens/gists{/gist_id}","starred_url":"https://api.github.com/users/mikestephens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikestephens/subscriptions","organizations_url":"https://api.github.com/users/mikestephens/orgs","repos_url":"https://api.github.com/users/mikestephens/repos","events_url":"https://api.github.com/users/mikestephens/events{/privacy}","received_events_url":"https://api.github.com/users/mikestephens/received_events","type":"User","site_admin":false},"body":"should this be `recent_builds_response`?","created_at":"2016-07-14T23:42:21Z","updated_at":"2016-07-14T23:42:21Z","html_url":"https://github.com/mikestephens/circle_reaper/pull/9#discussion_r70902573","pull_request_url":"https://api.github.com/repos/mikestephens/circle_reaper/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/mikestephens/circle_reaper/pulls/comments/70902573"},"html":{"href":"https://github.com/mikestephens/circle_reaper/pull/9#discussion_r70902573"},"pull_request":{"href":"https://api.github.com/repos/mikestephens/circle_reaper/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/mikestephens/circle_reaper/pulls/9","id":77543444,"html_url":"https://github.com/mikestephens/circle_reaper/pull/9","diff_url":"https://github.com/mikestephens/circle_reaper/pull/9.diff","patch_url":"https://github.com/mikestephens/circle_reaper/pull/9.patch","issue_url":"https://api.github.com/repos/mikestephens/circle_reaper/issues/9","number":9,"state":"open","locked":false,"title":"Pretty big refactor","user":{"login":"mikeastock","id":1907044,"avatar_url":"https://avatars.githubusercontent.com/u/1907044?v=3","gravatar_id":"","url":"https://api.github.com/users/mikeastock","html_url":"https://github.com/mikeastock","followers_url":"https://api.github.com/users/mikeastock/followers","following_url":"https://api.github.com/users/mikeastock/following{/other_user}","gists_url":"https://api.github.com/users/mikeastock/gists{/gist_id}","starred_url":"https://api.github.com/users/mikeastock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikeastock/subscriptions","organizations_url":"https://api.github.com/users/mikeastock/orgs","repos_url":"https://api.github.com/users/mikeastock/repos","events_url":"https://api.github.com/users/mikeastock/events{/privacy}","received_events_url":"https://api.github.com/users/mikeastock/received_events","type":"User","site_admin":false},"body":null,"created_at":"2016-07-14T23:37:18Z","updated_at":"2016-07-14T23:42:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1f1d5bca000037a1f5ee4a40a49acee3b6385a26","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mikestephens/circle_reaper/pulls/9/commits","review_comments_url":"https://api.github.com/repos/mikestephens/circle_reaper/pulls/9/comments","review_comment_url":"https://api.github.com/repos/mikestephens/circle_reaper/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mikestephens/circle_reaper/issues/9/comments","statuses_url":"https://api.github.com/repos/mikestephens/circle_reaper/statuses/774099b04185f8be197407e6ecc86513781aa06a","head":{"label":"mikestephens:refactor-worker","ref":"refactor-worker","sha":"774099b04185f8be197407e6ecc86513781aa06a","user":{"login":"mikestephens","id":1581475,"avatar_url":"https://avatars.githubusercontent.com/u/1581475?v=3","gravatar_id":"","url":"https://api.github.com/users/mikestephens","html_url":"https://github.com/mikestephens","followers_url":"https://api.github.com/users/mikestephens/followers","following_url":"https://api.github.com/users/mikestephens/following{/other_user}","gists_url":"https://api.github.com/users/mikestephens/gists{/gist_id}","starred_url":"https://api.github.com/users/mikestephens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikestephens/subscriptions","organizations_url":"https://api.github.com/users/mikestephens/orgs","repos_url":"https://api.github.com/users/mikestephens/repos","events_url":"https://api.github.com/users/mikestephens/events{/privacy}","received_events_url":"https://api.github.com/users/mikestephens/received_events","type":"User","site_admin":false},"repo":{"id":61563679,"name":"circle_reaper","full_name":"mikestephens/circle_reaper","owner":{"login":"mikestephens","id":1581475,"avatar_url":"https://avatars.githubusercontent.com/u/1581475?v=3","gravatar_id":"","url":"https://api.github.com/users/mikestephens","html_url":"https://github.com/mikestephens","followers_url":"https://api.github.com/users/mikestephens/followers","following_url":"https://api.github.com/users/mikestephens/following{/other_user}","gists_url":"https://api.github.com/users/mikestephens/gists{/gist_id}","starred_url":"https://api.github.com/users/mikestephens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikestephens/subscriptions","organizations_url":"https://api.github.com/users/mikestephens/orgs","repos_url":"https://api.github.com/users/mikestephens/repos","events_url":"https://api.github.com/users/mikestephens/events{/privacy}","received_events_url":"https://api.github.com/users/mikestephens/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mikestephens/circle_reaper","description":"Cancel multiple CircleCI builds that are from the same branch","fork":false,"url":"https://api.github.com/repos/mikestephens/circle_reaper","forks_url":"https://api.github.com/repos/mikestephens/circle_reaper/forks","keys_url":"https://api.github.com/repos/mikestephens/circle_reaper/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mikestephens/circle_reaper/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mikestephens/circle_reaper/teams","hooks_url":"https://api.github.com/repos/mikestephens/circle_reaper/hooks","issue_events_url":"https://api.github.com/repos/mikestephens/circle_reaper/issues/events{/number}","events_url":"https://api.github.com/repos/mikestephens/circle_reaper/events","assignees_url":"https://api.github.com/repos/mikestephens/circle_reaper/assignees{/user}","branches_url":"https://api.github.com/repos/mikestephens/circle_reaper/branches{/branch}","tags_url":"https://api.github.com/repos/mikestephens/circle_reaper/tags","blobs_url":"https://api.github.com/repos/mikestephens/circle_reaper/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mikestephens/circle_reaper/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mikestephens/circle_reaper/git/refs{/sha}","trees_url":"https://api.github.com/repos/mikestephens/circle_reaper/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mikestephens/circle_reaper/statuses/{sha}","languages_url":"https://api.github.com/repos/mikestephens/circle_reaper/languages","stargazers_url":"https://api.github.com/repos/mikestephens/circle_reaper/stargazers","contributors_url":"https://api.github.com/repos/mikestephens/circle_reaper/contributors","subscribers_url":"https://api.github.com/repos/mikestephens/circle_reaper/subscribers","subscription_url":"https://api.github.com/repos/mikestephens/circle_reaper/subscription","commits_url":"https://api.github.com/repos/mikestephens/circle_reaper/commits{/sha}","git_commits_url":"https://api.github.com/repos/mikestephens/circle_reaper/git/commits{/sha}","comments_url":"https://api.github.com/repos/mikestephens/circle_reaper/comments{/number}","issue_comment_url":"https://api.github.com/repos/mikestephens/circle_reaper/issues/comments{/number}","contents_url":"https://api.github.com/repos/mikestephens/circle_reaper/contents/{+path}","compare_url":"https://api.github.com/repos/mikestephens/circle_reaper/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mikestephens/circle_reaper/merges","archive_url":"https://api.github.com/repos/mikestephens/circle_reaper/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mikestephens/circle_reaper/downloads","issues_url":"https://api.github.com/repos/mikestephens/circle_reaper/issues{/number}","pulls_url":"https://api.github.com/repos/mikestephens/circle_reaper/pulls{/number}","milestones_url":"https://api.github.com/repos/mikestephens/circle_reaper/milestones{/number}","notifications_url":"https://api.github.com/repos/mikestephens/circle_reaper/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mikestephens/circle_reaper/labels{/name}","releases_url":"https://api.github.com/repos/mikestephens/circle_reaper/releases{/id}","deployments_url":"https://api.github.com/repos/mikestephens/circle_reaper/deployments","created_at":"2016-06-20T16:38:52Z","updated_at":"2016-06-21T16:29:07Z","pushed_at":"2016-07-14T23:39:52Z","git_url":"git://github.com/mikestephens/circle_reaper.git","ssh_url":"git@github.com:mikestephens/circle_reaper.git","clone_url":"https://github.com/mikestephens/circle_reaper.git","svn_url":"https://github.com/mikestephens/circle_reaper","homepage":null,"size":26,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"mikestephens:master","ref":"master","sha":"294f790a6e22ce003c611fc37213fb59284b122f","user":{"login":"mikestephens","id":1581475,"avatar_url":"https://avatars.githubusercontent.com/u/1581475?v=3","gravatar_id":"","url":"https://api.github.com/users/mikestephens","html_url":"https://github.com/mikestephens","followers_url":"https://api.github.com/users/mikestephens/followers","following_url":"https://api.github.com/users/mikestephens/following{/other_user}","gists_url":"https://api.github.com/users/mikestephens/gists{/gist_id}","starred_url":"https://api.github.com/users/mikestephens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikestephens/subscriptions","organizations_url":"https://api.github.com/users/mikestephens/orgs","repos_url":"https://api.github.com/users/mikestephens/repos","events_url":"https://api.github.com/users/mikestephens/events{/privacy}","received_events_url":"https://api.github.com/users/mikestephens/received_events","type":"User","site_admin":false},"repo":{"id":61563679,"name":"circle_reaper","full_name":"mikestephens/circle_reaper","owner":{"login":"mikestephens","id":1581475,"avatar_url":"https://avatars.githubusercontent.com/u/1581475?v=3","gravatar_id":"","url":"https://api.github.com/users/mikestephens","html_url":"https://github.com/mikestephens","followers_url":"https://api.github.com/users/mikestephens/followers","following_url":"https://api.github.com/users/mikestephens/following{/other_user}","gists_url":"https://api.github.com/users/mikestephens/gists{/gist_id}","starred_url":"https://api.github.com/users/mikestephens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikestephens/subscriptions","organizations_url":"https://api.github.com/users/mikestephens/orgs","repos_url":"https://api.github.com/users/mikestephens/repos","events_url":"https://api.github.com/users/mikestephens/events{/privacy}","received_events_url":"https://api.github.com/users/mikestephens/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mikestephens/circle_reaper","description":"Cancel multiple CircleCI builds that are from the same branch","fork":false,"url":"https://api.github.com/repos/mikestephens/circle_reaper","forks_url":"https://api.github.com/repos/mikestephens/circle_reaper/forks","keys_url":"https://api.github.com/repos/mikestephens/circle_reaper/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mikestephens/circle_reaper/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mikestephens/circle_reaper/teams","hooks_url":"https://api.github.com/repos/mikestephens/circle_reaper/hooks","issue_events_url":"https://api.github.com/repos/mikestephens/circle_reaper/issues/events{/number}","events_url":"https://api.github.com/repos/mikestephens/circle_reaper/events","assignees_url":"https://api.github.com/repos/mikestephens/circle_reaper/assignees{/user}","branches_url":"https://api.github.com/repos/mikestephens/circle_reaper/branches{/branch}","tags_url":"https://api.github.com/repos/mikestephens/circle_reaper/tags","blobs_url":"https://api.github.com/repos/mikestephens/circle_reaper/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mikestephens/circle_reaper/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mikestephens/circle_reaper/git/refs{/sha}","trees_url":"https://api.github.com/repos/mikestephens/circle_reaper/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mikestephens/circle_reaper/statuses/{sha}","languages_url":"https://api.github.com/repos/mikestephens/circle_reaper/languages","stargazers_url":"https://api.github.com/repos/mikestephens/circle_reaper/stargazers","contributors_url":"https://api.github.com/repos/mikestephens/circle_reaper/contributors","subscribers_url":"https://api.github.com/repos/mikestephens/circle_reaper/subscribers","subscription_url":"https://api.github.com/repos/mikestephens/circle_reaper/subscription","commits_url":"https://api.github.com/repos/mikestephens/circle_reaper/commits{/sha}","git_commits_url":"https://api.github.com/repos/mikestephens/circle_reaper/git/commits{/sha}","comments_url":"https://api.github.com/repos/mikestephens/circle_reaper/comments{/number}","issue_comment_url":"https://api.github.com/repos/mikestephens/circle_reaper/issues/comments{/number}","contents_url":"https://api.github.com/repos/mikestephens/circle_reaper/contents/{+path}","compare_url":"https://api.github.com/repos/mikestephens/circle_reaper/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mikestephens/circle_reaper/merges","archive_url":"https://api.github.com/repos/mikestephens/circle_reaper/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mikestephens/circle_reaper/downloads","issues_url":"https://api.github.com/repos/mikestephens/circle_reaper/issues{/number}","pulls_url":"https://api.github.com/repos/mikestephens/circle_reaper/pulls{/number}","milestones_url":"https://api.github.com/repos/mikestephens/circle_reaper/milestones{/number}","notifications_url":"https://api.github.com/repos/mikestephens/circle_reaper/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mikestephens/circle_reaper/labels{/name}","releases_url":"https://api.github.com/repos/mikestephens/circle_reaper/releases{/id}","deployments_url":"https://api.github.com/repos/mikestephens/circle_reaper/deployments","created_at":"2016-06-20T16:38:52Z","updated_at":"2016-06-21T16:29:07Z","pushed_at":"2016-07-14T23:39:52Z","git_url":"git://github.com/mikestephens/circle_reaper.git","ssh_url":"git@github.com:mikestephens/circle_reaper.git","clone_url":"https://github.com/mikestephens/circle_reaper.git","svn_url":"https://github.com/mikestephens/circle_reaper","homepage":null,"size":26,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mikestephens/circle_reaper/pulls/9"},"html":{"href":"https://github.com/mikestephens/circle_reaper/pull/9"},"issue":{"href":"https://api.github.com/repos/mikestephens/circle_reaper/issues/9"},"comments":{"href":"https://api.github.com/repos/mikestephens/circle_reaper/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/mikestephens/circle_reaper/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/mikestephens/circle_reaper/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mikestephens/circle_reaper/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/mikestephens/circle_reaper/statuses/774099b04185f8be197407e6ecc86513781aa06a"}}}}
{"actor":{"display_login":"mikestephens"}}