diff --git a/.github/workflows/close-issues-on-merge.yml b/.github/workflows/close-issues-on-merge.yml index 4c411c3365..df0682a9c1 100644 --- a/.github/workflows/close-issues-on-merge.yml +++ b/.github/workflows/close-issues-on-merge.yml @@ -26,19 +26,21 @@ jobs: - name: "Find and close linked issues" env: GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }} + GH_REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_URL: ${{ github.event.pull_request.html_url }} run: | - PR_BODY=$(gh pr view ${{ github.event.pull_request.number }} --repo "${{ github.repository }}" --json body --jq '.body') + mapfile -t URLS < <( + gh pr view "$PR_NUMBER" --json closingIssuesReferences --jq '.closingIssuesReferences[].url' + ) - # Parse "Closes/Fixes https://github.com/phpstan/phpstan/issues/123" patterns - 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) - - if [ -z "$URLS" ]; then - echo "No linked issues found in PR body" + if (( ${#URLS[@]} == 0 )); then + echo "No issues are linked to this PR" exit 0 fi - echo "$URLS" | while read -r url; do - NUMBER=$(echo "$url" | grep -oP '[0-9]+$') - echo "Closing phpstan/phpstan#${NUMBER}" - gh issue close "$NUMBER" --repo "phpstan/phpstan" --comment "Closed via merging ${{ github.event.pull_request.html_url }}" + for issue_url in "${URLS[@]}"; do + issue_number=${issue_url##*/} + echo "Closing phpstan/phpstan#${issue_number}" + gh issue close "$issue_url" --comment "Closed via merging $PR_URL" done