forked from conda-forge/staged-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (130 loc) · 5.43 KB
/
automate-review-labels.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: 'Automated review labels'
on:
issue_comment:
types: [ created ]
issues:
types: [ unlabeled, labeled ]
pull_request_target:
types: [ unlabeled, labeled ]
permissions:
issues: write # for adding label to an issue
pull-requests: write # for adding label to a pr
jobs:
add-review-team-label:
name: 'When pinged, label a PR with review team'
if: >
github.event.issue && github.event.issue.pull_request
runs-on: ubuntu-latest
steps:
- name: check-teams
id: check_teams
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const teams = [
'@conda-forge/staged-recipes',
'@conda-forge/help-c-cpp',
'@conda-forge/help-cdts',
'@conda-forge/help-go',
'@conda-forge/help-java',
'@conda-forge/help-julia',
'@conda-forge/help-nodejs',
'@conda-forge/help-perl',
'@conda-forge/help-python',
'@conda-forge/help-python-c',
'@conda-forge/help-r',
'@conda-forge/help-ruby',
'@conda-forge/help-rust'
];
let found_label = false;
for (const team of teams) {
let text = context.payload.comment.body;
const regex = new RegExp(team + '[^\w-]|' + team + '$');
let result = regex.test(text);
if (result) {
const slug = team.replace("@conda-forge/", "");
const label = slug.replace("help-", "");
found_label = true;
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [label, 'review-requested']
});
// NOTE: GitHub Actions default token lacks permission to
// assign teams for review; external bot required for
// that feature.
//
https://github.com/conda-forge/staged-recipes/issues/18023#issuecomment-1080451231
console.log(`Somebody mentioned ${slug}.`);
if (label == "staged-recipes") {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'To help direct your pull request to the best reviewers, ' +
'please mention a topic-specifc team if your recipe matches any of the following: ' +
'conda-forge/help-c-cpp, ' +
'conda-forge/help-cdts, ' +
'conda-forge/help-go, ' +
'conda-forge/help-java, ' +
'conda-forge/help-julia, ' +
'conda-forge/help-nodejs, ' +
'conda-forge/help-perl, ' +
'conda-forge/help-python, ' +
'conda-forge/help-python-c, ' +
'conda-forge/help-r, ' +
'conda-forge/help-ruby,' +
'or ' +
'conda-forge/help-rust' +
'. ' +
'Thanks!'
});
}
}
}
return found_label;
- name: remove-labels
if: >
(steps.check_teams.outputs.result == 'true') && contains(github.event.issue.labels.*.name, 'Awaiting author contribution')
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ['Awaiting author contribution']
})
add-await-when-review-removed:
name: 'Add awaiting-author when review-requested removed'
if: >
github.event.action == 'unlabeled' && github.event.label.name == 'review-requested'
runs-on: ubuntu-latest
steps:
- name: add-labels
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['Awaiting author contribution']
});
remove-review-when-await-added:
name: 'Removed review-requested when awaiting-author added'
if: >
github.event.action == 'labeled' && github.event.label.name == 'Awaiting author contribution'
runs-on: ubuntu-latest
steps:
- name: remove-labels
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ['review-requested']
})