-
-
Save jkakar/9537907 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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