Created
December 16, 2015 07:59
-
-
Save hamakn/2138765c40c3cff29bff to your computer and use it in GitHub Desktop.
open pull request
This file contains hidden or 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
#!perl | |
use strict; | |
use warnings; | |
# ref: http://techlife.cookpad.com/entry/2015/11/17/151426 | |
my $commit_hash = $ARGV[0]; | |
unless ($commit_hash) { | |
print "usage: open_pull_request <commit_hash>\n"; | |
exit; | |
} | |
my @merge_commits_1 = split "\n", `git rev-list --ancestry-path $commit_hash..master`; | |
my @merge_commits_2 = split "\n", `git rev-list --first-parent $commit_hash..master`; | |
my $target_commit; | |
my %cnt = (); | |
for (@merge_commits_1, @merge_commits_2) { | |
$target_commit = $_ if ++$cnt{$_} == 2; | |
} | |
if (!$target_commit || !`git show $target_commit | grep 'pull request'`) { | |
print "no pull request found\n"; | |
exit; | |
} | |
`git log -1 --format=%B $target_commit | head -1` =~ /^.*#([0-9]*).*$/; | |
my $url = "https://github.com/<account>/<repo>/pull/$1"; | |
print "$url\n"; | |
`open $url`; |
This file contains hidden or 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
#!ruby | |
# ref: http://techlife.cookpad.com/entry/2015/11/17/151426 | |
unless ARGV[0] | |
puts "usage: open_pull_request <commit hash>" | |
exit | |
end | |
merge_commits_1 = `git rev-list --ancestry-path #{ARGV[0]}..master`.split("\n") | |
merge_commits_2 = `git rev-list --first-parent #{ARGV[0]}..master`.split("\n") | |
merge_commit = (merge_commits_1 & merge_commits_2).last | |
unless merge_commit | |
puts "no pull request found" | |
exit | |
end | |
pull_request = `git show #{merge_commit} | grep 'pull request'` | |
unless pull_request | |
puts "no pull request found" | |
exit | |
end | |
`git log -1 --format=%B #{merge_commit}` =~ /^.*#([0-9]*).*$/ | |
pull_request_number = $1 | |
url = "https://github.com/<account>/<repo>/pull/#{pull_request_number}" | |
puts url | |
`open #{url}` |
This file contains hidden or 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
#!/bin/sh | |
# http://techlife.cookpad.com/entry/2015/11/17/151426 | |
merge_commit=$(ruby -e 'print (File.readlines(ARGV[0]) & File.readlines(ARGV[1])).last' <(git rev-list --ancestry-path $1..master) <(git rev-list --first-parent $1..master)) | |
if git show $merge_commit | grep -q 'pull request' | |
then | |
pull_request_number=$(git log -1 --format=%B $merge_commit | sed -e 's/^.*#\([0-9]*\).*$/\1/' | head -1) | |
url="https://github.com/<account>/<repo>/pull/${pull_request_number}" | |
fi | |
echo $url | |
open $url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment