Skip to content

Commit a7fb2ea

Browse files
authored
Merge pull request #265 from Homebrew/sync-shared-config
Synchronize shared configuration
2 parents 5b3f41e + 77e4924 commit a7fb2ea

1 file changed

Lines changed: 51 additions & 3 deletions

File tree

‎.github/workflows/check-prs.yml‎

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ jobs:
8989
grep -qF "Created by https://github.com/mislav/bump-homebrew-formula-action" "${RUNNER_TEMP}/check-prs/body"
9090
then
9191
echo "complete_template=true" >>"${GITHUB_OUTPUT:?}"
92+
echo "has_description=true" >>"${GITHUB_OUTPUT}"
9293
exit 0
9394
fi
9495
fi
@@ -100,15 +101,23 @@ jobs:
100101
"${PR_TITLE}" \
101102
"${GITHUB_REPOSITORY:?}"
102103
)"
103-
case "${complete_template}" in
104-
true | false) ;;
104+
has_description="$(
105+
ruby "${RUNNER_TEMP}/check_template.rb" pull-request-description \
106+
"${RUNNER_TEMP}/check-prs/body" \
107+
"${RUNNER_TEMP}/check-prs/template" \
108+
"${PR_TITLE}" \
109+
"${GITHUB_REPOSITORY}"
110+
)"
111+
case "${complete_template}:${has_description}" in
112+
true:true | true:false | false:true | false:false) ;;
105113
*)
106-
echo "Unexpected template completion result: ${complete_template}" >&2
114+
echo "Unexpected template/description result: ${complete_template}:${has_description}" >&2
107115
exit 1
108116
;;
109117
esac
110118
111119
echo "complete_template=${complete_template}" >>"${GITHUB_OUTPUT:?}"
120+
echo "has_description=${has_description}" >>"${GITHUB_OUTPUT}"
112121
113122
- name: Find incomplete template comment
114123
id: comments
@@ -133,6 +142,7 @@ jobs:
133142
echo "closed_by=${closed_by}" >>"${GITHUB_OUTPUT:?}"
134143
135144
- name: Reopen completed pull request
145+
id: reopen
136146
if: >-
137147
github.event.pull_request.state == 'closed' &&
138148
steps.template.outputs.complete_template == 'true' &&
@@ -176,3 +186,41 @@ jobs:
176186
run: |
177187
gh api --method PATCH "repos/${GITHUB_REPOSITORY:?}/pulls/${PR_NUMBER:?}" \
178188
-f state=closed
189+
190+
- name: Find missing description comment
191+
id: description_comments
192+
run: |
193+
gh api --paginate "repos/${GITHUB_REPOSITORY:?}/issues/${PR_NUMBER:?}/comments" \
194+
--jq '.[] | select(.user.login == "github-actions[bot]" and (.body | contains("<!-- missing-pr-description -->"))) | .id' \
195+
>"${RUNNER_TEMP:?}/check-prs/missing-description-comment-ids"
196+
if [[ -s "${RUNNER_TEMP}/check-prs/missing-description-comment-ids" ]]
197+
then
198+
echo "has_missing_description_comment=true" >>"${GITHUB_OUTPUT:?}"
199+
else
200+
echo "has_missing_description_comment=false" >>"${GITHUB_OUTPUT:?}"
201+
fi
202+
203+
- name: Remove resolved description comments
204+
if: >-
205+
steps.template.outputs.has_description == 'true' &&
206+
steps.description_comments.outputs.has_missing_description_comment == 'true'
207+
run: |
208+
while IFS= read -r comment_id
209+
do
210+
gh api --method DELETE "repos/${GITHUB_REPOSITORY:?}/issues/comments/${comment_id}"
211+
done <"${RUNNER_TEMP:?}/check-prs/missing-description-comment-ids"
212+
213+
- name: Comment on missing description
214+
if: >-
215+
(github.event.pull_request.state != 'closed' || steps.reopen.outcome == 'success') &&
216+
steps.template.outputs.complete_template == 'true' &&
217+
steps.template.outputs.has_description == 'false' &&
218+
steps.description_comments.outputs.has_missing_description_comment != 'true'
219+
run: |
220+
gh api --method POST "repos/${GITHUB_REPOSITORY:?}/issues/${PR_NUMBER:?}/comments" \
221+
--raw-field body="$(
222+
cat <<'COMMENT'
223+
<!-- missing-pr-description -->
224+
Please add a short description explaining what this pull request changes and why. This helps reviewers and makes the change easier to understand when investigating bugs later.
225+
COMMENT
226+
)"

0 commit comments

Comments
 (0)