-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpr_create.sh
67 lines (60 loc) · 1.81 KB
/
pr_create.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# !/bin/bash
set -e
BASE_REF="dev"
HEAD_REF="automated-release-dev"
PR_TITLE="ci: automated-release-dev"
REPOSITORY_OWNER="code-kern-ai"
REPOSITORY_NAME=""
REPOSITORY_PR_NUMBER=""
KUBERNETES_CLUSTER_REPO_NAME=""
while getopts b:h:t:o:r:n:k: flag
do
case "${flag}" in
b) BASE_REF=${OPTARG};;
h) HEAD_REF=${OPTARG};;
t) PR_TITLE=${OPTARG};;
o) REPOSITORY_OWNER=${OPTARG};;
r) REPOSITORY_NAME=${OPTARG};;
n) REPOSITORY_PR_NUMBER=${OPTARG};;
k) KUBERNETES_CLUSTER_REPO_NAME=${OPTARG};;
esac
done
EXISTING_PR_NUMBER=""
EXISTING_PR_BODY=$(gh pr list --base $BASE_REF --head $HEAD_REF --json body --jq '.[].body')
if [ -z "$EXISTING_PR_BODY" ]; then
if [[ $REPOSITORY_PR_NUMBER =~ ^v(0|[1-9]*)\.(0|[1-9]*)\.(0|[1-9]*) ]]; then
PR_BODY=$(cat <<EOF
Automated $BASE_REF release for:
- https://github.com/$REPOSITORY_OWNER/$REPOSITORY_NAME/releases/tag/$REPOSITORY_PR_NUMBER
EOF
)
else
PR_BODY=$(cat <<EOF
Automated $BASE_REF release for:
- https://github.com/$REPOSITORY_OWNER/$REPOSITORY_NAME/pull/$REPOSITORY_PR_NUMBER
EOF
)
fi
gh pr create \
--base $BASE_REF \
--head $HEAD_REF \
--title "$PR_TITLE" \
--body "$PR_BODY" \
--draft \
--repo $REPOSITORY_OWNER/$KUBERNETES_CLUSTER_REPO_NAME
# --reviewer $REPOSITORY_OWNER/devops-admin \
else
EXISTING_PR_NUMBER=$(gh pr list \
--base $BASE_REF \
--head $HEAD_REF \
--repo $REPOSITORY_OWNER/$KUBERNETES_CLUSTER_REPO_NAME \
--json number --jq '.[].number')
PR_BODY=$(cat <<EOF
$EXISTING_PR_BODY
- https://github.com/$REPOSITORY_OWNER/$REPOSITORY_NAME/pull/$REPOSITORY_PR_NUMBER
EOF
)
gh pr edit $EXISTING_PR_NUMBER \
--body "$PR_BODY" \
--repo $REPOSITORY_OWNER/$KUBERNETES_CLUSTER_REPO_NAME || true
fi