-
Notifications
You must be signed in to change notification settings - Fork 8
81 lines (67 loc) · 2.79 KB
/
pr_management.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
81
name: Auto Label PRs, then add assignees and reviewers automatically.
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
add_labels_reviewers_assignees:
name: Add labels, then reviewers & assignees
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Label PR based on content
id: label-pr
uses: actions/github-script@v7
with:
script: |
const labels = {
'alternative addition template': 'add mod',
'site changes template': 'enhancement',
'chore/documentation template': 'documentation'
};
const body = context.payload.pull_request.body.toLowerCase();
const foundLabels = Object.entries(labels)
.filter(([keyword]) => body.includes(keyword))
.map(([, label]) => label);
if (foundLabels.length > 0) {
await github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: foundLabels
});
}
return { labels: foundLabels };
- name: Set Reviewers and Assignees
if: steps.label-pr.outputs.labels != '[]'
uses: actions/github-script@v7
with:
script: |
const labelToReviewers = {
'add mod': ['KTrain5169', 'blryface'],
'enhancement': ['WorldWidePixel', 'Nitrrine'],
'documentation': ['blryface', 'KTrain5169', 'WorldWidePixel']
};
const labels = JSON.parse('${{ steps.label-pr.outputs.labels }}').labels;
const reviewers = new Set();
labels.forEach(label => {
(labelToReviewers[label] || []).forEach(reviewer => reviewers.add(reviewer));
});
if (reviewers.size > 0) {
await github.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
reviewers: Array.from(reviewers)
});
}
await github.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
assignees: [context.payload.pull_request.user.login]
});
- name: Comment on PRs
uses: dannyskoog/pull-request-comment@v1
with:
message: I've labeled your PR, assigned you and requested reviews from the relevant people automatically. If you think I did it wrong, please comment below so one of our maintainers can double-check. Thanks!