Skip to content

Commit df68192

Browse files
committed
Fix merging workflow
1 parent af658f3 commit df68192

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

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

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,18 @@ jobs:
1919
env:
2020
GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }}
2121
run: |
22-
# Query GraphQL for closing issues references
23-
ISSUES=$(gh api graphql -f query='
24-
query ($owner:String!, $repo:String!, $pr:Int!) {
25-
repository(owner:$owner, name:$repo) {
26-
pullRequest(number:$pr) {
27-
closingIssuesReferences(first:100) {
28-
nodes { number url repository { nameWithOwner } }
29-
}
30-
}
31-
}
32-
}
33-
' -f owner="${{ github.repository_owner }}" -f repo="${{ github.event.repository.name }}" -F pr=${{ github.event.pull_request.number }} --jq '.data.repository.pullRequest.closingIssuesReferences.nodes[]')
22+
PR_BODY=$(gh pr view ${{ github.event.pull_request.number }} --repo "${{ github.repository }}" --json body --jq '.body')
3423
35-
if [ -z "$ISSUES" ]; then
36-
echo "No linked issues found"
24+
# Parse "Closes/Fixes https://github.com/phpstan/phpstan/issues/123" patterns
25+
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)
26+
27+
if [ -z "$URLS" ]; then
28+
echo "No linked issues found in PR body"
3729
exit 0
3830
fi
3931
40-
echo "$ISSUES" | jq -c '.' | while read -r issue; do
41-
REPO=$(echo "$issue" | jq -r '.repository.nameWithOwner')
42-
NUMBER=$(echo "$issue" | jq -r '.number')
43-
URL=$(echo "$issue" | jq -r '.url')
44-
45-
echo "Closing $URL"
46-
gh issue close "$NUMBER" --repo "$REPO" --comment "Closed via merging ${{ github.event.pull_request.html_url }}"
32+
echo "$URLS" | while read -r url; do
33+
NUMBER=$(echo "$url" | grep -oP '[0-9]+$')
34+
echo "Closing phpstan/phpstan#${NUMBER}"
35+
gh issue close "$NUMBER" --repo "phpstan/phpstan" --comment "Closed via merging ${{ github.event.pull_request.html_url }}"
4736
done

0 commit comments

Comments
 (0)