-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgh-pull
More file actions
executable file
·51 lines (46 loc) · 1.15 KB
/
Copy pathgh-pull
File metadata and controls
executable file
·51 lines (46 loc) · 1.15 KB
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
#!/bin/bash
set -efu +o posix
unset pick pickopts merge
for o do
shift
case "$o" in
-e|-s|-n|-m|-x|--no-ff|--ff) pickopts+=("$o") ;;
--cherry-pick|--pick) pick=y ;;
--ff|--ff-only|--no-ff) pickopts+=("$o") ;&
--merge) merge=y ;;
*) set -- "$@" "$o"
esac
done
get_base() {
local url=$1 owner repo
if [[ $url =~ https://github.com/([^/]+)/(.*) ]]; then
owner=${BASH_REMATCH[1]}
repo=${BASH_REMATCH[2]}
repo=${repo%.git}
else
echo >&2 "OWNER/REPO unknown."
exit 1
fi
curl -sSLf "https://api.github.com/repos/$owner/$repo/pulls/$PR" \
| jq -r .base.sha
}
PR=${1:?pull request id}
if [[ $PR =~ (https://github.com/.*/.*)/(pull/[[:digit:]]+) ]]; then
url=${BASH_REMATCH[1]}
pr=${BASH_REMATCH[2]}
(set -x; git fetch "$url.git" "$pr/head")
elif [[ $PR =~ ^[[:digit:]]+$ ]]; then
url=$(git remote get-url origin)
(set -x; git fetch origin "pull/$PR/head")
else
echo >&2 "Unknown URL format"
exit 1
fi
if [ -v pick ]; then
base=$(get_base "$url")
git l "$base..FETCH_HEAD"
gum confirm 'Pick?'
(set -x; git cherry-pick "${pickopts[@]}" "$base..FETCH_HEAD")
elif [ -v merge ]; then
(set -x; git merge "${pickopts[@]}" FETCH_HEAD)
fi