-
Notifications
You must be signed in to change notification settings - Fork 3
181 lines (157 loc) · 6.69 KB
/
squad-label-enforce.yml
File metadata and controls
181 lines (157 loc) · 6.69 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: Squad Label Enforce
on:
issues:
types: [labeled]
permissions:
issues: write
contents: read
jobs:
enforce:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Enforce mutual exclusivity
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue;
const appliedLabel = context.payload.label.name;
// Namespaces with mutual exclusivity rules
const EXCLUSIVE_PREFIXES = ['go:', 'release:', 'type:', 'priority:'];
// Skip if not a managed namespace label
if (!EXCLUSIVE_PREFIXES.some(p => appliedLabel.startsWith(p))) {
core.info(`Label ${appliedLabel} is not in a managed namespace — skipping`);
return;
}
const allLabels = issue.labels.map(l => l.name);
// Handle go: namespace (mutual exclusivity)
if (appliedLabel.startsWith('go:')) {
const otherGoLabels = allLabels.filter(l =>
l.startsWith('go:') && l !== appliedLabel
);
if (otherGoLabels.length > 0) {
// Remove conflicting go: labels
for (const label of otherGoLabels) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: label
});
core.info(`Removed conflicting label: ${label}`);
}
// Post update comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `🏷️ Triage verdict updated → \`${appliedLabel}\``
});
}
// Auto-apply release:backlog if go:yes and no release target
if (appliedLabel === 'go:yes') {
const hasReleaseLabel = allLabels.some(l => l.startsWith('release:'));
if (!hasReleaseLabel) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['release:backlog']
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `📋 Marked as \`release:backlog\` — assign a release target when ready.`
});
core.info('Applied release:backlog for go:yes issue');
}
}
// Remove release: labels if go:no
if (appliedLabel === 'go:no') {
const releaseLabels = allLabels.filter(l => l.startsWith('release:'));
if (releaseLabels.length > 0) {
for (const label of releaseLabels) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: label
});
core.info(`Removed release label from go:no issue: ${label}`);
}
}
}
}
// Handle release: namespace (mutual exclusivity)
if (appliedLabel.startsWith('release:')) {
const otherReleaseLabels = allLabels.filter(l =>
l.startsWith('release:') && l !== appliedLabel
);
if (otherReleaseLabels.length > 0) {
// Remove conflicting release: labels
for (const label of otherReleaseLabels) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: label
});
core.info(`Removed conflicting label: ${label}`);
}
// Post update comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `🏷️ Release target updated → \`${appliedLabel}\``
});
}
}
// Handle type: namespace (mutual exclusivity)
if (appliedLabel.startsWith('type:')) {
const otherTypeLabels = allLabels.filter(l =>
l.startsWith('type:') && l !== appliedLabel
);
if (otherTypeLabels.length > 0) {
for (const label of otherTypeLabels) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: label
});
core.info(`Removed conflicting label: ${label}`);
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `🏷️ Issue type updated → \`${appliedLabel}\``
});
}
}
// Handle priority: namespace (mutual exclusivity)
if (appliedLabel.startsWith('priority:')) {
const otherPriorityLabels = allLabels.filter(l =>
l.startsWith('priority:') && l !== appliedLabel
);
if (otherPriorityLabels.length > 0) {
for (const label of otherPriorityLabels) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: label
});
core.info(`Removed conflicting label: ${label}`);
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: `🏷️ Priority updated → \`${appliedLabel}\``
});
}
}
core.info(`Label enforcement complete for ${appliedLabel}`);