Skip to content

Commit 9ac78c0

Browse files
committed
Do not parse PR body to find issues to close
Extracting linked issues from PR body is very hard as there are variety of syntaxes to link an issue. https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword We should use `closingIssuesReferences` instead.
1 parent 001d465 commit 9ac78c0

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

.github/workflows/close-issues-on-merge.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,17 @@ jobs:
2727
env:
2828
GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }}
2929
run: |
30-
PR_BODY=$(gh pr view ${{ github.event.pull_request.number }} --repo "${{ github.repository }}" --json body --jq '.body')
30+
URLS=(
31+
$(gh pr view ${{ github.event.pull_request.number }} --repo "$GITHUB_REPOSITORY" --json closingIssuesReferences --jq '.closingIssuesReferences[].url')
32+
)
3133
32-
# Parse "Closes/Fixes https://github.com/phpstan/phpstan/issues/123" patterns
33-
URLS=$(echo "$PR_BODY" | grep -oiP '(?:closes?|fix(?:es)?)\s+https://github\.com/phpstan/phpstan/issues/[0-9]+' | grep -oP 'https://github\.com/phpstan/phpstan/issues/[0-9]+' || true)
34-
35-
if [ -z "$URLS" ]; then
36-
echo "No linked issues found in PR body"
34+
if (( ${#URLS[@]} == 0 )); then
35+
echo "No issues are linked to this PR"
3736
exit 0
3837
fi
3938
40-
echo "$URLS" | while read -r url; do
41-
NUMBER=$(echo "$url" | grep -oP '[0-9]+$')
39+
for url in "${URLS[@]}"; do
40+
NUMBER=${url##*/}
4241
echo "Closing phpstan/phpstan#${NUMBER}"
43-
gh issue close "$NUMBER" --repo "phpstan/phpstan" --comment "Closed via merging ${{ github.event.pull_request.html_url }}"
42+
gh issue close "$url" --comment "Closed via merging ${{ github.event.pull_request.html_url }}"
4443
done

0 commit comments

Comments
 (0)