Repository navigation
98 lines (85 loc) · 3.56 KB
/
Copy pathauto-label-issues.yml
File metadata and controls
98 lines (85 loc) · 3.56 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
name: Auto Label Issues
on:
issues:
types: [opened]
jobs:
auto-label:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- uses: actions/github-script@v7
with:
script: |
const body = context.payload.issue.body || '';
const labels = [];
// =====================
// 1. DETECTION (all labels gathered before any apply)
// =====================
// --- Detect commands owned by other teams ---
const commandMatch = body.match(/### Command\s*\n\s*(.+)/);
const command = commandMatch ? commandMatch[1].trim().toLowerCase() : '';
const otherTeamCommands = [
{ match: 'project deploy pipeline', area: 'area:devops' },
{ match: 'devops', area: 'area:devops' },
{ match: 'org create shape', area: 'area:signups' },
{ match: 'org create snapshot', area: 'area:signups' },
];
// Sort longest match first to avoid partial matches
otherTeamCommands.sort((a, b) => b.match.length - a.match.length);
for (const { match, area } of otherTeamCommands) {
if (command.includes(match)) {
labels.push(area);
labels.push('owned by another team');
break;
}
}
// Agent commands — match "sf agent" but not flags like --agent
if (/\bsf\s+agent\b/.test(command) || /^agent\b/.test(command)) {
labels.push('area:afdx');
labels.push('bug');
if (!labels.includes('owned by another team')) labels.push('owned by another team');
}
// --- Parse regression ---
const regressionMatch = body.match(/### Did this work before\?\s*\n\s*(.+)/);
const regression = regressionMatch ? regressionMatch[1].trim() : '';
if (regression === 'Yes, this is a regression') labels.push('regression');
// =====================
// 2. APPLY LABELS (single pass, all labels at once)
// =====================
const labelColors = {
'owned by another team': { color: 'e99695', description: 'Bug is owned by another team' },
};
const uniqueLabels = [...new Set(labels)];
// Create labels that don't exist yet (area: labels already exist on repo)
for (const name of uniqueLabels) {
const config = labelColors[name];
if (!config) continue;
try {
await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name,
});
} catch (e) {
if (e.status === 404) {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name,
color: config.color,
description: config.description,
});
}
}
}
// Apply all labels at once
if (uniqueLabels.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: uniqueLabels,
});
}
console.log(`Labels applied: ${uniqueLabels.join(', ') || 'none'}`);