-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (105 loc) · 4.16 KB
/
pr-controller.yaml
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
name: PR Controller
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
add-labels:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Assign Zerohertz to PR
if: github.event_name == 'pull_request' && github.event.action == 'opened'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_TOKEN}}
script: |
github.rest.issues.addAssignees({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
assignees: ['Zerohertz']
})
- name: Add labels based on file path and branch
uses: actions/github-script@v6
with:
github-token: ${{secrets.GH_TOKEN}}
script: |
const baseBranch = context.payload.pull_request.base.ref;
const headBranch = context.payload.pull_request.head.ref;
const issueNumber = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
let labelsToAdd = [];
// Check for PR from dev* to master
if (baseBranch === 'master' && headBranch.startsWith('dev')) {
const files = await github.rest.pulls.listFiles({
owner,
repo,
pull_number: issueNumber
});
files.data.forEach(file => {
labelsToAdd.push('release');
if (file.filename.startsWith('Jenkins') || file.filename.startsWith('.github/workflows')) {
labelsToAdd.push('chore');
}
if (file.filename.startsWith('docs')) {
labelsToAdd.push('docs');
}
if (file.filename.startsWith('zerohertzLib/algorithm/')) {
labelsToAdd.push('feat/algorithm');
}
if (file.filename.startsWith('zerohertzLib/api/')) {
labelsToAdd.push('feat/api');
}
if (file.filename.startsWith('zerohertzLib/logging/')) {
labelsToAdd.push('feat/logging');
}
if (file.filename.startsWith('zerohertzLib/mlops/')) {
labelsToAdd.push('feat/mlops');
}
if (file.filename.startsWith('zerohertzLib/monitoring/')) {
labelsToAdd.push('feat/monitoring');
}
if (file.filename.startsWith('zerohertzLib/plot/')) {
labelsToAdd.push('feat/plot');
}
if (file.filename.startsWith('zerohertzLib/util/')) {
labelsToAdd.push('feat/util');
}
if (file.filename.startsWith('zerohertzLib/vision/')) {
labelsToAdd.push('feat/vision');
}
});
}
// Check for PR from docs-* to master
if (baseBranch === 'master' && headBranch.startsWith('docs-')) {
const files = await github.rest.pulls.listFiles({
owner,
repo,
pull_number: issueNumber
});
files.data.forEach(file => {
labelsToAdd.push('release/docs');
if (file.filename.startsWith('Jenkins') || file.filename.startsWith('.github/workflows')) {
labelsToAdd.push('chore');
}
if (file.filename.startsWith('docs')) {
labelsToAdd.push('docs');
}
});
}
// Check for PR from docs to dev* or docs*
if ((baseBranch.startsWith('dev') || baseBranch.startsWith('docs')) && headBranch === 'docs') {
labelsToAdd.push('docs');
}
// Remove duplicates
labelsToAdd = [...new Set(labelsToAdd)];
if (labelsToAdd.length > 0) {
await github.rest.issues.addLabels({
issue_number: issueNumber,
owner,
repo,
labels: labelsToAdd
});
}