{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/jarvis/pulls/comments/45487358","id":45487358,"diff_hunk":"@@ -1,15 +1,127 @@\n require \"clamp\"\n+require \"fileutils\"\n+require \"octokit\"\n+require \"mustache\"\n+require \"open4\"\n+require \"cabin\"\n+require \"i18n\"\n+require \"git\"\n+require \"stud/temporary\"\n+require \"jarvis/github/pull_request\"\n+require \"jarvis/git\"\n+require \"jarvis/fetch\"\n+require \"jarvis/defer\"\n+require \"mbox\"\n \n module Jarvis module Command class Merge < Clamp::Command\n+  class PushFailure < ::Jarvis::Error; end\n+  class Bug < ::Jarvis::Error; end\n \n   banner \"Merge a pull request into one or more branches.\"\n \n+  option \"--committer-email\", \"EMAIL\", \"The git committer to set on all commits. If not set, the default is whatever your git defaults to (see `git config --get user.email` and `git config --get user.email`).\"\n+  option \"--committer-name\", \"NAME\", \"The git committer name to set on all commits. If not set, the default is whatever your git defaults to (see `git config --get user.name` and `git config --get user.email`).\"\n+\n+  option \"--workdir\", \"WORKDIR\", \"The place where this command will download temporary files and do stuff on disk to complete a given task.\"\n+  option \"--github-token\", \"GITHUB_TOKEN\", \"Your github auth token\", :required => true\n+\n   parameter \"URL\", \"The URL to merge\"\n-  parameter \"BRANCHES ...\", \"The branches to merge\"\n+  parameter \"BRANCHES ...\", \"The branches to merge\", :attribute_name => :branches\n+\n+  def pr\n+    @pr ||= Jarvis::GitHub::PullRequest.parse(url)\n+  end\n+\n+  def github\n+    return @github if @github\n+    @github = Octokit::Client.new\n+    @github.access_token = github_token\n+    @github.login\n+    @github\n+  end\n \n   def execute\n-    puts \"Merging: #{url} into #{branches_list}\"\n+    defer = ::Jarvis::Defer.new\n+    logs = []\n+    logger = ::Cabin::Channel.new\n+    logger.subscribe(logs)\n+    logger.subscribe(STDOUT) if STDOUT.tty?\n+    logger.level = :debug\n+    logger[:context] = \"#{pr.project}\\##{pr.number}\"\n+\n+    if workdir.nil?\n+      self.workdir = Stud::Temporary.pathname\n+      defer.do { FileUtils.rm_r(workdir, :secure => true) }","path":"lib/jarvis/commands/merge.rb","position":56,"original_position":56,"commit_id":"036dea6fec2d5c67e46b794c9732508d9c1367f9","original_commit_id":"036dea6fec2d5c67e46b794c9732508d9c1367f9","user":{"login":"jordansissel","id":131818,"avatar_url":"https://avatars.githubusercontent.com/u/131818?v=3","gravatar_id":"","url":"https://api.github.com/users/jordansissel","html_url":"https://github.com/jordansissel","followers_url":"https://api.github.com/users/jordansissel/followers","following_url":"https://api.github.com/users/jordansissel/following{/other_user}","gists_url":"https://api.github.com/users/jordansissel/gists{/gist_id}","starred_url":"https://api.github.com/users/jordansissel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordansissel/subscriptions","organizations_url":"https://api.github.com/users/jordansissel/orgs","repos_url":"https://api.github.com/users/jordansissel/repos","events_url":"https://api.github.com/users/jordansissel/events{/privacy}","received_events_url":"https://api.github.com/users/jordansissel/received_events","type":"User","site_admin":false},"body":"hehe :P","created_at":"2015-11-20T16:26:58Z","updated_at":"2015-11-20T16:26:58Z","html_url":"https://github.com/elastic/jarvis/pull/39#discussion_r45487358","pull_request_url":"https://api.github.com/repos/elastic/jarvis/pulls/39","_links":{"self":{"href":"https://api.github.com/repos/elastic/jarvis/pulls/comments/45487358"},"html":{"href":"https://github.com/elastic/jarvis/pull/39#discussion_r45487358"},"pull_request":{"href":"https://api.github.com/repos/elastic/jarvis/pulls/39"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/jarvis/pulls/39","id":50464308,"html_url":"https://github.com/elastic/jarvis/pull/39","diff_url":"https://github.com/elastic/jarvis/pull/39.diff","patch_url":"https://github.com/elastic/jarvis/pull/39.patch","issue_url":"https://api.github.com/repos/elastic/jarvis/issues/39","number":39,"state":"open","locked":false,"title":"Add lots of commands and improvements.","user":{"login":"jordansissel","id":131818,"avatar_url":"https://avatars.githubusercontent.com/u/131818?v=3","gravatar_id":"","url":"https://api.github.com/users/jordansissel","html_url":"https://github.com/jordansissel","followers_url":"https://api.github.com/users/jordansissel/followers","following_url":"https://api.github.com/users/jordansissel/following{/other_user}","gists_url":"https://api.github.com/users/jordansissel/gists{/gist_id}","starred_url":"https://api.github.com/users/jordansissel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordansissel/subscriptions","organizations_url":"https://api.github.com/users/jordansissel/orgs","repos_url":"https://api.github.com/users/jordansissel/repos","events_url":"https://api.github.com/users/jordansissel/events{/privacy}","received_events_url":"https://api.github.com/users/jordansissel/received_events","type":"User","site_admin":false},"body":"This is another large-sweep as part of the refactor/rewrite of Jarvis.\r\n\r\nMajor changes:\r\n\r\n* Clamp delegation now supports passing flag values that come from the request or Lita's environment (see the 'merge' command fancy_route example)\r\n* Implemented merge and cla commands.\r\n* Added user profile settings via `user set [key] [value]` and `user set [key]`. This is used for telling Lita what your git name+email are for the purposes of merging. (Fixes #16)\r\n* Much more logging is captured during merge execution and is published only on error. At this time, I think _all_ output from the merge command, on failure, will reach the user (instead of the console output!) for easier debugging.\r\n* Verified 'restart' command works.\r\n* Implemented ping command which also shows last-successful heartbeat time.\r\n* I tried to implement heartbeat but Lita will ignore its own messages :(\r\n* Added merge and publish commands.","created_at":"2015-11-12T02:21:21Z","updated_at":"2015-11-20T16:26:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"85df76e14143d3372453e8ff0acaba3893c93d65","assignee":{"login":"ph","id":640,"avatar_url":"https://avatars.githubusercontent.com/u/640?v=3","gravatar_id":"","url":"https://api.github.com/users/ph","html_url":"https://github.com/ph","followers_url":"https://api.github.com/users/ph/followers","following_url":"https://api.github.com/users/ph/following{/other_user}","gists_url":"https://api.github.com/users/ph/gists{/gist_id}","starred_url":"https://api.github.com/users/ph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ph/subscriptions","organizations_url":"https://api.github.com/users/ph/orgs","repos_url":"https://api.github.com/users/ph/repos","events_url":"https://api.github.com/users/ph/events{/privacy}","received_events_url":"https://api.github.com/users/ph/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/elastic/jarvis/pulls/39/commits","review_comments_url":"https://api.github.com/repos/elastic/jarvis/pulls/39/comments","review_comment_url":"https://api.github.com/repos/elastic/jarvis/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/jarvis/issues/39/comments","statuses_url":"https://api.github.com/repos/elastic/jarvis/statuses/036dea6fec2d5c67e46b794c9732508d9c1367f9","head":{"label":"elastic:add-some-commands","ref":"add-some-commands","sha":"036dea6fec2d5c67e46b794c9732508d9c1367f9","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":24524776,"name":"jarvis","full_name":"elastic/jarvis","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/jarvis","description":"Elasticsearch's ChatOps bot, J.A.R.V.I.S.","fork":false,"url":"https://api.github.com/repos/elastic/jarvis","forks_url":"https://api.github.com/repos/elastic/jarvis/forks","keys_url":"https://api.github.com/repos/elastic/jarvis/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/jarvis/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/jarvis/teams","hooks_url":"https://api.github.com/repos/elastic/jarvis/hooks","issue_events_url":"https://api.github.com/repos/elastic/jarvis/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/jarvis/events","assignees_url":"https://api.github.com/repos/elastic/jarvis/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/jarvis/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/jarvis/tags","blobs_url":"https://api.github.com/repos/elastic/jarvis/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/jarvis/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/jarvis/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/jarvis/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/jarvis/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/jarvis/languages","stargazers_url":"https://api.github.com/repos/elastic/jarvis/stargazers","contributors_url":"https://api.github.com/repos/elastic/jarvis/contributors","subscribers_url":"https://api.github.com/repos/elastic/jarvis/subscribers","subscription_url":"https://api.github.com/repos/elastic/jarvis/subscription","commits_url":"https://api.github.com/repos/elastic/jarvis/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/jarvis/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/jarvis/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/jarvis/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/jarvis/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/jarvis/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/jarvis/merges","archive_url":"https://api.github.com/repos/elastic/jarvis/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/jarvis/downloads","issues_url":"https://api.github.com/repos/elastic/jarvis/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/jarvis/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/jarvis/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/jarvis/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/jarvis/labels{/name}","releases_url":"https://api.github.com/repos/elastic/jarvis/releases{/id}","created_at":"2014-09-27T05:57:09Z","updated_at":"2015-11-20T14:53:04Z","pushed_at":"2015-11-19T19:39:26Z","git_url":"git://github.com/elastic/jarvis.git","ssh_url":"git@github.com:elastic/jarvis.git","clone_url":"https://github.com/elastic/jarvis.git","svn_url":"https://github.com/elastic/jarvis","homepage":"","size":159,"stargazers_count":7,"watchers_count":7,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":24,"forks":9,"open_issues":24,"watchers":7,"default_branch":"master"}},"base":{"label":"elastic:rewrite","ref":"rewrite","sha":"540ee36b075fd40cd38456cefad2126fd8da900c","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":24524776,"name":"jarvis","full_name":"elastic/jarvis","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/jarvis","description":"Elasticsearch's ChatOps bot, J.A.R.V.I.S.","fork":false,"url":"https://api.github.com/repos/elastic/jarvis","forks_url":"https://api.github.com/repos/elastic/jarvis/forks","keys_url":"https://api.github.com/repos/elastic/jarvis/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/jarvis/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/jarvis/teams","hooks_url":"https://api.github.com/repos/elastic/jarvis/hooks","issue_events_url":"https://api.github.com/repos/elastic/jarvis/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/jarvis/events","assignees_url":"https://api.github.com/repos/elastic/jarvis/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/jarvis/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/jarvis/tags","blobs_url":"https://api.github.com/repos/elastic/jarvis/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/jarvis/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/jarvis/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/jarvis/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/jarvis/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/jarvis/languages","stargazers_url":"https://api.github.com/repos/elastic/jarvis/stargazers","contributors_url":"https://api.github.com/repos/elastic/jarvis/contributors","subscribers_url":"https://api.github.com/repos/elastic/jarvis/subscribers","subscription_url":"https://api.github.com/repos/elastic/jarvis/subscription","commits_url":"https://api.github.com/repos/elastic/jarvis/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/jarvis/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/jarvis/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/jarvis/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/jarvis/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/jarvis/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/jarvis/merges","archive_url":"https://api.github.com/repos/elastic/jarvis/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/jarvis/downloads","issues_url":"https://api.github.com/repos/elastic/jarvis/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/jarvis/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/jarvis/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/jarvis/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/jarvis/labels{/name}","releases_url":"https://api.github.com/repos/elastic/jarvis/releases{/id}","created_at":"2014-09-27T05:57:09Z","updated_at":"2015-11-20T14:53:04Z","pushed_at":"2015-11-19T19:39:26Z","git_url":"git://github.com/elastic/jarvis.git","ssh_url":"git@github.com:elastic/jarvis.git","clone_url":"https://github.com/elastic/jarvis.git","svn_url":"https://github.com/elastic/jarvis","homepage":"","size":159,"stargazers_count":7,"watchers_count":7,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":24,"forks":9,"open_issues":24,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/jarvis/pulls/39"},"html":{"href":"https://github.com/elastic/jarvis/pull/39"},"issue":{"href":"https://api.github.com/repos/elastic/jarvis/issues/39"},"comments":{"href":"https://api.github.com/repos/elastic/jarvis/issues/39/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/jarvis/pulls/39/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/jarvis/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/jarvis/pulls/39/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/jarvis/statuses/036dea6fec2d5c67e46b794c9732508d9c1367f9"}}}}