-
Notifications
You must be signed in to change notification settings - Fork 54
81 lines (76 loc) · 2.61 KB
/
label_pr_merged.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Add "for test" Label
on:
pull_request_target:
types:
- closed
permissions:
pull-requests: read
issues: write
jobs:
add_label:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
outputs:
issue_id_list: ${{ steps.pr-commits.outputs.issue_id_list }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Get PR commits messages
id: pr-commits
uses: actions/github-script@v6
with:
script: |
const { data: commits } = await github.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ github.event.number }}
});
const messages = commits.map(commit => commit.commit.message);
console.log(messages.join("\n"));
const regex = /#(\d+)/g;
const issue_id_list = messages.join("\n").match(regex).map(match => match.replace("#", ""));
console.log(issue_id_list);
core.setOutput("issue_id_list", issue_id_list);
- name: Add label to issues
uses: actions/github-script@v6
with:
script: |
for (const issue_id of ${{ steps.pr-commits.outputs.issue_id_list }}) {
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_id
});
const todo_label = labels.find(label => label.name === "todo");
if (todo_label) {
github.rest.issues.removeLabel({
issue_number: issue_id,
owner: context.repo.owner,
repo: context.repo.repo,
name: "todo"
});
}
github.rest.issues.addLabels({
issue_number: issue_id,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["for test"]
});
}
- name: Close Issue
uses: peter-evans/close-issue@v3
with:
issue-number: 1
comment: Auto-closing issue
close_issue:
needs: add_label
runs-on: ubuntu-latest
strategy:
matrix:
issue_id: ${{ fromJSON(needs.add_label.outputs.issue_id_list) }}
steps:
- name: Close Issue ${{ matrix.issue_id }}
uses: peter-evans/close-issue@v3
with:
issue-number: ${{ matrix.issue_id }}
comment: Auto close issue after pr merged \#${{ github.event.number }}