Skip to content

Commit 3f5fd50

Browse files
Add a commit comment when creating an upstream PR via script
1 parent 16ec2e5 commit 3f5fd50

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

generate-stackbrew-pr.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ IMAGES_FILE="library/node"
2020
REPO_NAME="official-images"
2121
ORIGIN_SLUG="$GITHUB_USERNAME/$REPO_NAME"
2222
UPSTREAM_SLUG="docker-library/$REPO_NAME"
23+
DOCKER_SLUG="nodejs/docker-node"
2324
gitpath="$REPO_NAME"
2425

2526
function updated() {
@@ -86,6 +87,14 @@ function pr_payload() {
8687
}'
8788
}
8889

90+
function comment_payload() {
91+
local pr_url
92+
pr_url="$1"
93+
echo '{
94+
"body": "Created PR to the '"$REPO_NAME"' repo ('"$pr_url"')"
95+
}'
96+
}
97+
8998
if updated; then
9099

91100
permission_check
@@ -108,16 +117,32 @@ if updated; then
108117
info "Pushing..."
109118
git push "https://$GITHUB_API_TOKEN:[email protected]/$ORIGIN_SLUG.git" -f "$BRANCH_NAME" 2> /dev/null || fatal "Error pushing the updated stackbrew"
110119

120+
cd - && rm -rf $gitpath
121+
111122
info "Creating Pull request"
112123
pr_response_payload="$(curl -H "$(auth_header)" \
113124
-s \
114125
-X POST \
115126
-d "$(pr_payload)" \
116127
"https://api.github.com/repos/$UPSTREAM_SLUG/pulls")"
117128

118-
url="$(echo "$pr_response_payload" | jq .html_url)"
129+
url="$(echo "$pr_response_payload" | jq -r .html_url)"
119130
if [ "$url" != "null" ]; then
120131
info "Pull request created at $url"
132+
133+
info "Creating Commit Comment"
134+
commit_response_payload="$(curl -H "$(auth_header)" \
135+
-s \
136+
-X POST \
137+
-d "$(comment_payload "$url")" \
138+
"https://api.github.com/repos/$DOCKER_SLUG/commits/$COMMIT_ID/comments")"
139+
140+
if [ "$(echo "$commit_response_payload" | jq .message)" != "null" ]; then
141+
fatal "Error linking the pull request ($error_message)"
142+
else
143+
comment_url="$(echo "$commit_response_payload" | jq -r .html_url)"
144+
info "Created comment at $comment_url"
145+
fi
121146
else
122147
error_message=$(echo "$pr_response_payload" | jq .message)
123148
fatal "Error creating pull request ($error_message)"

0 commit comments

Comments
 (0)