-
Notifications
You must be signed in to change notification settings - Fork 3.5k
59 lines (55 loc) · 2.4 KB
/
Copy pathissue-labeler.yml
File metadata and controls
59 lines (55 loc) · 2.4 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
name: Issue area labeler
# Adds area labels to new/edited issues based on keyword regexes in
# .github/issue-labeler.yml. Additive only (addLabels never removes): it
# never touches a label a maintainer set by hand. Base bug/enhancement
# labels already come from the issue forms.
#
# Implemented with first-party actions/github-script (not a third-party
# labeler action) so every pattern is compiled as a JavaScript RegExp with
# the `i` flag applied centrally — inline `(?i)` groups are PCRE-only and
# threw `SyntaxError: Invalid group` on every issue (#764). A pattern that
# fails to compile now fails the run loudly instead of silently no-oping.
on:
issues:
types: [opened, edited]
permissions:
contents: read
jobs:
triage:
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const fs = require('fs');
const text = [context.payload.issue.title, context.payload.issue.body]
.filter(Boolean).join('\n');
const rules = [];
const bad = [];
// Config format: one rule per line — "label": 'regex' (see the
// header comment in .github/issue-labeler.yml).
for (const line of fs.readFileSync('.github/issue-labeler.yml', 'utf8').split('\n')) {
const m = line.match(/^"([^"]+)":\s*'(.*)'\s*$/);
if (!m) continue;
try { rules.push({ label: m[1], re: new RegExp(m[2], 'i') }); }
catch (e) { bad.push(`${m[1]}: ${e.message}`); }
}
if (rules.length === 0 && bad.length === 0) {
core.setFailed('no labeling rules parsed from .github/issue-labeler.yml');
return;
}
const labels = rules.filter(r => r.re.test(text)).map(r => r.label);
if (labels.length) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels,
});
}
core.info(`matched: ${labels.join(', ') || '(none)'}`);
if (bad.length) core.setFailed(`invalid label regex(es): ${bad.join('; ')}`);