File tree 1 file changed +66
-0
lines changed
1 file changed +66
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ #
3
+ # Copyright (c) 2022 Red Hat, Inc.
4
+ # This program and the accompanying materials are made
5
+ # available under the terms of the Eclipse Public License 2.0
6
+ # which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ #
8
+ # SPDX-License-Identifier: EPL-2.0
9
+ #
10
+ # Utility script to approve and merge a PR by URL
11
+ #
12
+
13
+ command -v gh > /dev/null 2>&1 || which gh > /dev/null 2>&1 || { echo " gh is not installed - must install from https://cli.github.com/" ; usage; exit 1; }
14
+
15
+ usage () {
16
+ cat << EOF
17
+ Usage: $0 [URL1] [URL2 ...] [OPTIONS]
18
+
19
+ Options:
20
+ -a : approve PR
21
+ -m : squash-merge PR
22
+ -v : verbose output
23
+ -h, --help : show this help
24
+
25
+ Example:
26
+ $0 -a -m https://github.com/eclipse-che/che-devfile-registry/pull/697/files
27
+ EOF
28
+ }
29
+
30
+ DO_APPROVE=0
31
+ DO_MERGE=0
32
+ VERBOSE=0
33
+
34
+ while [[ " $# " -gt 0 ]]; do
35
+ case $1 in
36
+ ' -a' |' --approve' ) DO_APPROVE=1;;
37
+ ' -m' |' --merge' ) DO_MERGE=1;;
38
+ ' -v' |' --verbose' ) VERBOSE=1;;
39
+ ' -h' |' --help' ) usage;;
40
+ * ) URLs=" $URLs $1 " ;;
41
+ esac
42
+ shift 1
43
+ done
44
+
45
+ for URL in $URLs ; do
46
+ R=$URL ; R=${R%/ pull/* } ; # echo $R
47
+ PR=$URL ; PR=${PR##*/ pull/ } ; PR=${PR%%/* } ; # echo $PR
48
+
49
+ if [[ $DO_APPROVE -eq 1 ]]; then
50
+ approve_cmd=" gh pr review $PR --approve -R $R "
51
+ if [[ VERBOSE -eq 1 ]]; then
52
+ echo " To approve:
53
+ $approve_cmd "
54
+ fi
55
+ $approve_cmd
56
+ fi
57
+
58
+ if [[ $DO_MERGE -eq 1 ]]; then
59
+ merge_cmd=" gh pr merge $PR -s -R $R "
60
+ if [[ VERBOSE -eq 1 ]]; then
61
+ echo " To merge:
62
+ $merge_cmd "
63
+ fi
64
+ $merge_cmd
65
+ fi
66
+ done
You can’t perform that action at this time.
0 commit comments