feat: improved and corrected existing github workflows #3
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Close Issues on PR Merge | |
on: | |
pull_request: | |
types: [closed] | |
permissions: | |
issues: write | |
pull-requests: read | |
jobs: | |
close-issues: | |
runs-on: ubuntu-latest | |
if: github.event.pull_request.merged == true | |
steps: | |
- name: Close linked issues | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const prBody = context.payload.pull_request.body || ''; | |
const prNumber = context.payload.pull_request.number; | |
// Find issue references using regex | |
const issueRefs = prBody.match(/#(\d+)/g) || []; | |
for (const ref of issueRefs) { | |
const issueNumber = ref.substring(1); | |
console.log(`Processing issue #${issueNumber}`); | |
try { | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.name, | |
issue_number: parseInt(issueNumber), | |
body: `🔗 This issue has been closed automatically because it was linked to pull request #${prNumber} which has been merged.\n\nIf you believe this issue still needs attention, please reopen it or create a new issue with additional details.` | |
}); | |
// Close the issue | |
await github.rest.issues.update({ | |
owner: context.repo.owner, | |
repo: context.repo.name, | |
issue_number: parseInt(issueNumber), | |
state: 'closed', | |
state_reason: 'completed' | |
}); | |
console.log(`Successfully closed issue #${issueNumber}`); | |
} catch (error) { | |
console.error(`Error processing issue #${issueNumber}:`, error); | |
} | |
} |