Skip to content

Instantly share code, notes, and snippets.

@jkakar
Created March 13, 2014 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkakar/9537907 to your computer and use it in GitHub Desktop.
Save jkakar/9537907 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# encoding: UTF-8
require 'rubygems'
require 'excon'
require 'json'
account, repo = `git config --get remote.origin.url`.strip.split(':').last.split('/')
repo = repo.split('.').first
branch = `git symbolic-ref HEAD`.strip.split('/').last
issue = ARGV.first
# make sure remote branch has latest and greatest from local
`git push --set-upstream origin #{branch}`
github = Excon.new(
'https://api.github.com',
:headers => {
'Authorization' => 'Basic ' << ['' << ENV['GITHUB_USER'] << ':' << ENV['GITHUB_PASS']].pack('m').delete(Excon::CR_NL),
'User-Agent' => 'ghpr'
},
:nonblock => false
)
puts "Converting issue ##{issue} to pull request."
# add commits in this branch to issue number specified by ARGV[0]
github.request(
:method => :post,
:path => "/repos/#{account}/#{repo}/pulls",
:body => {
:base => 'master',
:head => "#{account}:#{branch}",
:issue => issue
}.to_json
)
puts "Adding comment to cause notification."
# add a comment to the issue to indicate the added commits
github.request(
:method => :post,
:path => "/repos/#{account}/#{repo}/issues/#{issue}/comments",
:body => { :body => 'Commits added, converted to pull request.' }.to_json
)
puts "https://github.com/#{account}/#{repo}/pull/#{issue}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment