forked from 1jehuang/jcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_jcode_pr.sh
More file actions
executable file
·89 lines (77 loc) · 1.99 KB
/
create_jcode_pr.sh
File metadata and controls
executable file
·89 lines (77 loc) · 1.99 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'USAGE'
Usage: scripts/create_jcode_pr.sh [--upstream] [--allow-master-head] [gh-pr-create-args...]
Creates a jcode pull request with safe defaults.
Default target:
ShawnSantiago/jcode
Upstream target:
Pass --upstream explicitly to target 1jehuang/jcode.
Branch safety:
PRs from master are blocked by default. Use a feature branch, or pass
--allow-master-head only when explicitly approved.
Examples:
scripts/create_jcode_pr.sh --base master --head my-feature --title "Fix thing" --body "..."
scripts/create_jcode_pr.sh --upstream --base master --head ShawnSantiago:my-feature --title "Fix thing" --body "..."
USAGE
}
repo="ShawnSantiago/jcode"
allow_master_head=false
args=()
head_arg=""
while [[ $# -gt 0 ]]; do
case "$1" in
--upstream)
repo="1jehuang/jcode"
shift
;;
--allow-master-head)
allow_master_head=true
shift
;;
-h|--help)
usage
exit 0
;;
--repo|-R)
echo "error: --repo is managed by this wrapper; use --upstream only when explicitly targeting 1jehuang/jcode" >&2
exit 2
;;
--head)
if [[ $# -lt 2 ]]; then
echo "error: --head requires a value" >&2
exit 2
fi
head_arg="$2"
args+=("$1" "$2")
shift 2
;;
--head=*)
head_arg="${1#--head=}"
args+=("$1")
shift
;;
*)
args+=("$1")
shift
;;
esac
done
if [[ ${#args[@]} -eq 0 ]]; then
usage >&2
exit 2
fi
if [[ -z "${head_arg}" ]]; then
head_arg="$(git branch --show-current 2>/dev/null || true)"
fi
head_branch="${head_arg##*:}"
if [[ "${allow_master_head}" != true && "${head_branch}" == "master" ]]; then
cat >&2 <<'ERROR'
error: refusing to create a PR from master.
Create a feature branch first, or pass --allow-master-head only when explicitly approved.
ERROR
exit 2
fi
echo "Creating PR in ${repo} from head ${head_arg:-${head_branch}}" >&2
exec gh pr create --repo "${repo}" "${args[@]}"