-
Notifications
You must be signed in to change notification settings - Fork 104
48 lines (41 loc) · 1.46 KB
/
autoCloseLinkedIssues.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
name: 'Auto Close Linked Issues'
on:
pull_request_target:
types: [closed]
branches: [main, master]
jobs:
close-issues:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/checkout@v3
- name: Close Linked Issues
uses: actions/github-script@v6
with:
github-token: ${{ secrets.COFFEE_SHOP_GITHUB_TOKEN }}
script: |
const pr = context.payload.pull_request;
// Get issue numbers from PR title/body
const issueNumbers = [
...pr.title.match(/#(\d+)/g) || [],
...pr.body.match(/#(\d+)/g) || []
].map(num => Number(num.replace('#', '')));
// Process each linked issue
for (const issueNumber of issueNumbers) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: 'closed'
});
// Add completion comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `✅ This issue has been resolved in PR #${pr.number} by @${pr.user.login}`
});
}