-
Notifications
You must be signed in to change notification settings - Fork 27
37 lines (33 loc) · 1.24 KB
/
pullReqMerge.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
name: Comment on PR Closure and Close Related Issue
on:
pull_request_target:
types:
- closed
jobs:
close_issue:
runs-on: ubuntu-latest
steps:
- name: Check PR Merge Status
id: pr_status
run: echo "::set-output name=merged::${{ github.event.pull_request.merged }}"
- name: Close related issue if PR is merged
if: steps.pr_status.outputs.merged == 'true'
uses: actions/github-script@v4
with:
github-token: ${{ secrets.MY_SEC }}
script: |
const { owner, repo, number } = context.issue;
const linkedIssues = context.payload.pull_request.body.match(/#\d+/g); // Find issue numbers in the PR body (e.g. "closes #123")
if (linkedIssues) {
for (const issue of linkedIssues) {
const issue_number = issue.replace('#', ''); // Extract issue number
await github.issues.update({
owner,
repo,
issue_number,
state: 'closed'
});
console.log(`Closed issue: ${issue}`);
}
}
console.log('No linked issues found in the PR body.');