Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions .github/workflows/close-issues-on-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading