forked from conda-forge/staged-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (115 loc) · 4.45 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
name: 'Automated review labels'
on:
issue_comment:
types: [created]
issues:
types: [unlabeled]
pull_request_target:
types: [unlabeled]
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
&& !contains(github.event.issue.labels.*.name, 'review-requested')
runs-on: ubuntu-latest
steps:
- name: check-teams
id: check_teams
uses: actions/github-script@v6
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'
];
let found_label = false;
for (const team of teams) {
let text = context.payload.comment.body;
const regex = new RegExp(team + '[^\-]|' + 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}.`);
}
}
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@v6
with:
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ['Awaiting author contribution']
})
check-remove-review-requested-label:
name: 'Check that review-requested label was removed by a team member'
if: >
github.event.action == 'unlabeled'
&& github.event.label.name == 'review-requested'
runs-on: ubuntu-latest
steps:
- name: check-team-membership
id: check_team_review
uses: actions/github-script@v6
with:
script: |
console.log(`Label was removed by ${context.payload.sender.login}`);
return true;
- name: add-labels
if: >
(steps.check_team_review.outputs.result == 'true')
uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['Awaiting author contribution']
});
- name: readd-review-label
if: >
(steps.check_team_review.outputs.result == 'false')
uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['review-requested']
});
console.log('Non-members of staged recipes cannot remove this label.')