Last active
August 29, 2015 13:57
-
-
Save moxley/9401890 to your computer and use it in GitHub Desktop.
Create Pull Request from current branch
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 | |
# Open Pull Request for current branch | |
# Works in OS X | |
require 'ostruct' | |
branch=`git branch | grep '\*' | sed 's/\* //'` | |
remote_rows = `git remote -v | grep push`.split("\n").map do |line| | |
match = line.match(/^([^\s]+)\s+([^\s]+)/) | |
url = match[2] | |
tmp = url.gsub(/^(git@|https?:\/\/)/, ''). | |
gsub(/\.git$/, '') | |
match2 = tmp.match(/^([^:\/]+)[:\/](.*)$/) | |
OpenStruct.new(name: match[1], url: url, host: match2[1], path: '/' + match2[2]) | |
end | |
preferred_remote_row = if remote_rows.length == 1 | |
remote_rows.first | |
elsif remote_rows.length > 1 | |
# Assumes that if you have more than 1 remote, you don't want to push to origin | |
remote_rows.detect { |r| r.name != 'origin' } | |
else | |
raise "No remotes found to push to: git remote -v | grep push" | |
end | |
r = preferred_remote_row | |
cmd = "open https://#{r.host}#{r.path}/pull/new/#{branch}" | |
exec cmd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment