1616 fi
1717fi
1818
19+ if [[ " $COMMIT_MESSAGE " =~ Merge\ pull\ request\ \# ([0-9]* ) ]]; then
20+
21+ # This is a merge from a pull request
22+ PR_NUMBER=" ${BASH_REMATCH[1]} "
23+ COMMIT_MESSAGE=" $( printf " %s" " $COMMIT_MESSAGE " | tail -n 1) "
24+ fi
25+
1926IMAGES_FILE=" library/node"
2027REPO_NAME=" official-images"
2128ORIGIN_SLUG=" $GITHUB_USERNAME /$REPO_NAME "
2229UPSTREAM_SLUG=" docker-library/$REPO_NAME "
30+ DOCKER_SLUG=" nodejs/docker-node"
2331gitpath=" $REPO_NAME "
2432
2533function updated() {
@@ -86,6 +94,14 @@ function pr_payload() {
8694 }'
8795}
8896
97+ function comment_payload() {
98+ local pr_url
99+ pr_url=" $1 "
100+ echo ' {
101+ "body": "Created PR to the ' " $REPO_NAME " ' repo (' " $pr_url " ' )"
102+ }'
103+ }
104+
89105if updated; then
90106
91107 permission_check
@@ -108,16 +124,38 @@ if updated; then
108124 info " Pushing..."
109125 git push " https://$GITHUB_API_TOKEN :x-oauth-basic@github.com/$ORIGIN_SLUG .git" -f " $BRANCH_NAME " 2> /dev/null || fatal " Error pushing the updated stackbrew"
110126
127+ cd - && rm -rf $gitpath
128+
111129 info " Creating Pull request"
112130 pr_response_payload=" $( curl -H " $( auth_header) " \
113131 -s \
114132 -X POST \
115133 -d " $( pr_payload) " \
116134 " https://api.github.com/repos/$UPSTREAM_SLUG /pulls" ) "
117135
118- url=" $( echo " $pr_response_payload " | jq .html_url) "
136+ url=" $( echo " $pr_response_payload " | jq -r .html_url) "
119137 if [ " $url " != " null" ]; then
120138 info " Pull request created at $url "
139+
140+ if [ ! -z " $PR_NUMBER " ]; then
141+ comment_endpoint=" https://api.github.com/repos/$DOCKER_SLUG /issues/$PR_NUMBER /comments"
142+ else
143+ comment_endpoint=" https://api.github.com/repos/$DOCKER_SLUG /commits/$COMMIT_ID /comments"
144+ fi
145+
146+ info " Creating Commit Comment"
147+ commit_response_payload=" $( curl -H " $( auth_header) " \
148+ -s \
149+ -X POST \
150+ -d " $( comment_payload " $url " ) " \
151+ " $comment_endpoint " ) "
152+
153+ if [ " $( echo " $commit_response_payload " | jq .message) " != " null" ]; then
154+ fatal " Error linking the pull request ($error_message )"
155+ else
156+ comment_url=" $( echo " $commit_response_payload " | jq -r .html_url) "
157+ info " Created comment at $comment_url "
158+ fi
121159 else
122160 error_message=$( echo " $pr_response_payload " | jq .message)
123161 fatal " Error creating pull request ($error_message )"
0 commit comments