-
Notifications
You must be signed in to change notification settings - Fork 2
/
git-hub-pull-request
executable file
·63 lines (49 loc) · 1.69 KB
/
git-hub-pull-request
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
#
# Create a GitHub pull request: calls `git prepare` and `git push`,
# followed by one of the following: `gh pr create`, `hub pull-request`, or
# opening a GitHub compare URL.
set -e # stop on error
SCRIPTS="$(dirname "$0")"
upstream=$("$SCRIPTS"/git-hub-remotes --upstream | cut -f1)
fork=$("$SCRIPTS"/git-hub-remotes --fork | cut -f1)
current=$(git symbolic-ref --short HEAD)
git prepare "$upstream"
git push "$fork"
sleep 1
# If the `gh` command is available, use it to create and open the pull request.
if which hub > /dev/null; then
echo
echo "Creating pull request..."
echo "> gh pr create --fill --web"
gh pr create --fill --web
exit
fi
# If the `hub` command is available, use it to create and open the pull request.
if which hub > /dev/null; then
echo
echo "Creating pull request..."
echo "> hub pull-request --browse"
hub pull-request --browse
exit
fi
# Otherwise, construct a compare URL and attempt to open it.
upstream_url=$("$SCRIPTS"/git-hub-remotes --upstream | cut -f2)
fork_url=$("$SCRIPTS"/git-hub-remotes --fork | cut -f2)
upstream_repo=$(echo "$upstream_url" | sed 's/.*github.com.//' | cut -f1 -d.)
fork_repo=$(echo $"fork_url" | sed 's/.*github.com.//' | cut -f1 -d/)
url="https://github.com/$upstream_repo/compare/main...$fork_repo:$branch"
echo
BROWSER_COMMANDS="open xdg-open cygstart x-www-browser google-chrome firefox"
for $browser in $BROWSER_COMMANDS; do
if which $browser > /dev/null; then
echo "Opening GitHub compare page..."
echo "> $browser $url"
$browser "$url"
exit
fi
done
echo "Error: Could not automatically open the GitHub compare page."
echo "Please go to the following URL to create the pull request:"
echo
echo " $url"