11name : Issue area labeler
22
33# Adds area labels to new/edited issues based on keyword regexes in
4- # .github/issue-labeler.yml. Additive only (sync-labels off): it never
5- # removes a label a maintainer set by hand. Base bug/enhancement labels
6- # already come from the issue forms.
4+ # .github/issue-labeler.yml. Additive only (addLabels never removes): it
5+ # never touches a label a maintainer set by hand. Base bug/enhancement
6+ # labels already come from the issue forms.
7+ #
8+ # Implemented with first-party actions/github-script (not a third-party
9+ # labeler action) so every pattern is compiled as a JavaScript RegExp with
10+ # the `i` flag applied centrally — inline `(?i)` groups are PCRE-only and
11+ # threw `SyntaxError: Invalid group` on every issue (#764). A pattern that
12+ # fails to compile now fails the run loudly instead of silently no-oping.
713
814on :
915 issues :
@@ -16,13 +22,38 @@ jobs:
1622 triage :
1723 runs-on : ubuntu-latest
1824 permissions :
25+ contents : read
1926 issues : write
2027 steps :
21- - uses : github/issue-labeler@c1b0f9f52a63158c4adc09425e858e87b32e9685 # v3.4
28+ - uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
29+ - uses : actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
2230 with :
23- configuration-path : .github/issue-labeler.yml
24- enable-versioned-regex : 0
25- include-title : 1
26- include-body : 1
27- sync-labels : 0
28- repo-token : ${{ secrets.GITHUB_TOKEN }}
31+ script : |
32+ const fs = require('fs');
33+ const text = [context.payload.issue.title, context.payload.issue.body]
34+ .filter(Boolean).join('\n');
35+ const rules = [];
36+ const bad = [];
37+ // Config format: one rule per line — "label": 'regex' (see the
38+ // header comment in .github/issue-labeler.yml).
39+ for (const line of fs.readFileSync('.github/issue-labeler.yml', 'utf8').split('\n')) {
40+ const m = line.match(/^"([^"]+)":\s*'(.*)'\s*$/);
41+ if (!m) continue;
42+ try { rules.push({ label: m[1], re: new RegExp(m[2], 'i') }); }
43+ catch (e) { bad.push(`${m[1]}: ${e.message}`); }
44+ }
45+ if (rules.length === 0 && bad.length === 0) {
46+ core.setFailed('no labeling rules parsed from .github/issue-labeler.yml');
47+ return;
48+ }
49+ const labels = rules.filter(r => r.re.test(text)).map(r => r.label);
50+ if (labels.length) {
51+ await github.rest.issues.addLabels({
52+ owner: context.repo.owner,
53+ repo: context.repo.repo,
54+ issue_number: context.issue.number,
55+ labels,
56+ });
57+ }
58+ core.info(`matched: ${labels.join(', ') || '(none)'}`);
59+ if (bad.length) core.setFailed(`invalid label regex(es): ${bad.join('; ')}`);
0 commit comments