-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (115 loc) · 4.98 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
118
119
120
121
122
123
124
125
126
127
128
name: PR Controller
on:
pull_request:
types: [opened, 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;
const body = context.payload.pull_request.body.toLowerCase();
let labelsToAdd = [];
if (body.includes('bug') || body.includes('fix') || body.includes('수정')) {
labelsToAdd.push('fix');
}
if (body.includes('style')) {
labelsToAdd.push('style');
}
// 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('sphinx') && !file.filename.includes('release')) {
labelsToAdd.push('docs');
}
if (file.filename.startsWith('zerohertzLib/algorithm/__init__') || body.includes('algorithm')) {
labelsToAdd.push('feat/algorithm');
}
if (file.filename.startsWith('zerohertzLib/api/__init__') || body.includes('api')) {
labelsToAdd.push('feat/api');
}
if (file.filename.startsWith('zerohertzLib/logging/__init__') || body.includes('logging')) {
labelsToAdd.push('feat/logging');
}
if (file.filename.startsWith('zerohertzLib/mlops/__init__') || body.includes('mlops')) {
labelsToAdd.push('feat/mlops');
}
if (file.filename.startsWith('zerohertzLib/monitoring/__init__') || body.includes('monitoring')) {
labelsToAdd.push('feat/monitoring');
}
if (file.filename.startsWith('zerohertzLib/plot/__init__') || body.includes('plot')) {
labelsToAdd.push('feat/plot');
}
if (file.filename.startsWith('zerohertzLib/quant/__init__') || body.includes('quant')) {
labelsToAdd.push('feat/quant');
}
if (file.filename.startsWith('zerohertzLib/util/__init__') || body.includes('util')) {
labelsToAdd.push('feat/util');
}
if (file.filename.startsWith('zerohertzLib/vision/__init__') || body.includes('vision')) {
labelsToAdd.push('feat/vision');
}
});
}
// Check for PR from chore-* to master
if (baseBranch === 'master' && headBranch.startsWith('chore')) {
const files = await github.rest.pulls.listFiles({
owner,
repo,
pull_number: issueNumber
});
files.data.forEach(file => {
labelsToAdd.push('release/chore');
if (file.filename.startsWith('Jenkins') || file.filename.startsWith('.github/workflows')) {
labelsToAdd.push('chore');
}
if (file.filename.startsWith('sphinx') && !file.filename.includes('release')) {
labelsToAdd.push('docs');
}
});
}
// Check for PR from docs to dev* or chore*
if ((baseBranch.startsWith('dev') || baseBranch.startsWith('chore')) && 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
});
}