16
16
fi
17
17
fi
18
18
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
+
19
26
IMAGES_FILE=" library/node"
20
27
REPO_NAME=" official-images"
21
28
ORIGIN_SLUG=" $GITHUB_USERNAME /$REPO_NAME "
22
29
UPSTREAM_SLUG=" docker-library/$REPO_NAME "
30
+ DOCKER_SLUG=" nodejs/docker-node"
23
31
gitpath=" $REPO_NAME "
24
32
25
33
function updated() {
@@ -86,6 +94,14 @@ function pr_payload() {
86
94
}'
87
95
}
88
96
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
+
89
105
if updated; then
90
106
91
107
permission_check
@@ -108,16 +124,38 @@ if updated; then
108
124
info " Pushing..."
109
125
git push
" https://$GITHUB_API_TOKEN :[email protected] /$ORIGIN_SLUG .git" -f
" $BRANCH_NAME " 2> /dev/null
|| fatal
" Error pushing the updated stackbrew"
110
126
127
+ cd - && rm -rf $gitpath
128
+
111
129
info " Creating Pull request"
112
130
pr_response_payload=" $( curl -H " $( auth_header) " \
113
131
-s \
114
132
-X POST \
115
133
-d " $( pr_payload) " \
116
134
" https://api.github.com/repos/$UPSTREAM_SLUG /pulls" ) "
117
135
118
- url=" $( echo " $pr_response_payload " | jq .html_url) "
136
+ url=" $( echo " $pr_response_payload " | jq -r .html_url) "
119
137
if [ " $url " != " null" ]; then
120
138
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
121
159
else
122
160
error_message=$( echo " $pr_response_payload " | jq .message)
123
161
fatal " Error creating pull request ($error_message )"
0 commit comments