-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpr-merge.sh
executable file
·43 lines (33 loc) · 933 Bytes
/
pr-merge.sh
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
#!/bin/bash
script_dir="$(dirname "$0")"
if ! "$script_dir/check.sh"; then
exit 1
fi
source $script_dir/base.sh
source $script_dir/pr-jira.sh
pr_id=$1
if [ -z "$pr_id" ]; then
pr_url=$(gh pr status --json url -q '.currentBranch.url')
pr_id=$(echo "$pr_url" | grep -oE '[0-9]+$')
if [ -n $"$pr_id" ]; then
echo -e $y Find current branch PR: $pr_url
fi
fi
while [ -z "$pr_id" ]; do
read -p 'PR id(require): ' pr_id
done
echo 'Do you want to continue merging PR? (y/n)'
read choice
if [ ! "$choice" = "y" ]; then
exit 0
fi
# 首先尝试 squash 合并
if ! gh pr merge $pr_id --squash --delete-branch; then
echo -e "${y}Squash merge failed, trying normal merge...${n}"
# 如果 squash 合并失败,尝试普通合并
if ! gh pr merge $pr_id --merge --delete-branch; then
echo -e "${r}Both squash and normal merge failed${n}"
exit 1
fi
fi
jira_merge $pr_id