Skip to content
Merged
Changes from 10 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
38 changes: 38 additions & 0 deletions .github/workflows/auto-close-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Close Linked Issues on PR Merge

on:
pull_request:
types:
- closed
branches:
- 2.0
- dev-2.0

jobs:
close_issues:
if: github.event.pull_request.merged == true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

runs-on: ubuntu-latest
steps:
- name: Extract and Close Issues
uses: actions/github-script@v7
with:
script: |
const prBody = context.payload.pull_request.body;
const issueRegex = /(Fixes|Resolves|Closes)\s+#(\d+)/gi;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: consider making more flexible? Eg /(close[sd]?|fix(e[sd])?|resolve[sd]?)[:\s]*#(\d+)/gi or something like that to more match the level of flexibility that happens on the main branch. While this is a bit more complex, I think matching behavior between these branches might be worth doing, what do you thi nk @perminder-17 ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aah, yes, that sounds great to me and also very flexible as well. It would help ensure consistency with the main branch’s behavior.

let match;
while ((match = issueRegex.exec(prBody)) !== null) {
const issueNumber = parseInt(match[2], 10);
console.log(`Closing issue #${issueNumber}`);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `Closed by merged PR #${context.payload.pull_request.number}`
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: "closed"
});
}
Loading