forked from magma/magma
-
Notifications
You must be signed in to change notification settings - Fork 1
159 lines (149 loc) · 6.48 KB
/
autolabel-pullrequests.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Copyright 2022 The Magma Authors.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# owner: @magma/approvers-infra
# purpose: Add labels to a PR based on changed code
# remediation: -
name: PR Generate Labels
on:
# Use pull_request_target to gain write permissions.
# Ref: https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/
pull_request_target:
types: [ opened, reopened, synchronize ]
paths:
- '.github/**'
- 'ci-scripts/**'
- 'cn/**'
- 'cwf/**'
- 'docs/**'
- 'dp/**'
- 'example/**'
- 'experimental/**'
- 'feg/**'
- 'lte/**'
- 'nms/**'
- 'openwrt/**'
- 'orc8r/**'
- 'protos/**'
- 'scripts/**'
- 'secrets/**'
- 'show-tech/**'
- 'third_party/**'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
AutoLabelPR:
runs-on: ubuntu-20.04
steps:
- uses: actions/github-script@d556feaca394842dc55e4734bf3bb9f685482fa0 # [email protected]
with:
script: |
let newCompLbls = new Set(); // Set of new label strings
// Fetch files modified in the PR
const pulledFiles = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
// Identify new component labels based on the files modified in the PR
for (const f of pulledFiles['data']) {
switch (true) {
case /^ci-scripts\/.*/.test(f.filename):
case /^\.github\/workflows\/.*/.test(f.filename):
case /^third_party\/build\/.*/.test(f.filename):
case /^orc8r\/tools\/packer\/.*/.test(f.filename):
case /^orc8r\/cloud\/deploy\/bare-metal\/.*/.test(f.filename):
case /^orc8r\/cloud\/deploy\/bare-metal-ansible\/.*/.test(f.filename):
case /^lte\/gateway\/docker\/.*/.test(f.filename):
case /^lte\/gateway\/release\/.*/.test(f.filename):
case /^lte\/gateway\/Vagrantfile/.test(f.filename):
case /^cwf\/gateway\/Vagrantfile/.test(f.filename):
console.log("file changed under CI component : " + f['filename']);
newCompLbls.add("component: ci");
break;
case /^nms\/.*/.test(f.filename):
console.log("file changed under NMS component : " + f['filename']);
newCompLbls.add("component: nms");
break;
case /^cwf\/.*/.test(f.filename):
case /^feg\/radius\/.*/.test(f.filename):
console.log("file changed under CWF component : " + f['filename']);
newCompLbls.add("component: cwf");
break;
case /^feg\/.*/.test(f.filename):
console.log("file changed under FEG component : " + f['filename']);
newCompLbls.add("component: feg");
break;
case /^openwrt\/.*/.test(f.filename):
console.log("file changed under OPENWRT component : " + f['filename']);
newCompLbls.add("component: openwrt");
break;
case /^lte\/gateway\/.*/.test(f.filename):
case /^lte\/protos\/.*/.test(f.filename):
case /^orc8r\/gateway\/c\/.*/.test(f.filename):
case /^third_party\/gtp_ovs\/.*/.test(f.filename):
console.log("file changed under AGW component : " + f['filename']);
newCompLbls.add("component: agw");
break;
case /.*\/cloud\/.*/.test(f.filename):
case /^\.golangci\.yml/.test(f.filename):
case /^orc8r\/.*/.test(f.filename):
console.log("file changed under ORC8R component : " + f['filename']);
newCompLbls.add("component: orc8r");
break;
case /^show-tech\/.*/.test(f.filename):
console.log("file changed under SHOW-TECH component : " + f['filename']);
newCompLbls.add("component: show-tech");
break;
case /^docs\/.*/.test(f.filename):
console.log("file changed under DOCS: " + f['filename']);
newCompLbls.add("component: docs");
break;
case /^dp\/.*/.test(f.filename):
console.log("file changed under DP component: " + f['filename']);
newCompLbls.add("component: dp");
break;
} // end of switch case
} // end of for loop
const curLblObjs = await github.rest.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
// Delete current component labels from PR that are no more valid
for (const l of curLblObjs['data']) {
//console.log("Current LabelName: " + l['name'] + " LabelDescription: " + l['description']);
if(l['name'].startsWith("component: ")) {
if(newCompLbls.has(l['name'])) {
newCompLbls.delete(l['name']);
}
else {
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: l['name'],
});
}
} // end of if block
} // end of for loop
if( newCompLbls.size == 0 ) {
console.log("No new component files changed in this PR: " + context.issue.number);
}
else {
let uniqLbls = Array.from(newCompLbls);
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: uniqLbls,
});
} // end of else block