返回 CodeWhale
triage.yml
根目录 / .github / workflows / triage.yml
1 name: Issue triage
2
3 on:
4 issues:
5 types: [opened, reopened]
6
7 permissions:
8 issues: write
9 contents: read
10
11 jobs:
12 label:
13 runs-on: ubuntu-latest
14 steps:
15 - name: Auto-label by title and body
16 uses: actions/github-script@v9
17 with:
18 script: |
19 const issue = context.payload.issue;
20 const title = (issue.title || '').toLowerCase();
21 const body = (issue.body || '').toLowerCase();
22 const text = `${title}\n${body}`;
23 const labels = new Set();
24
25 // Type — matched against the TITLE only.
26 //
27 // These ran against title+body and mislabelled long, well-specified
28 // issues. Any body containing an acceptance criterion like "fails
29 // when a pack drifts" matched the bug rule, and a "How to add a
30 // locale" heading matched the question rule, so planned work landed
31 // tagged `bug, question`. A title states the type; a body just
32 // discusses it. `error`/`fail` are dropped entirely — they describe
33 // what almost every issue talks about, not what any issue *is*.
34 if (/\b(bug|crash|panic|broken|stack ?trace|regression)\b/.test(title)) labels.add('bug');
35 if (/\b(feat(?:ure)?|request|enhancement|wishlist|proposal|please add|would be nice|support for)\b/.test(title)) labels.add('enhancement');
36 if (/\b(docs?|readme|documentation|typo|grammar|wording|spelling)\b/.test(title)) labels.add('documentation');
37 if (/\b(question|how (?:do|to)|why does|what does|is it possible)\b/.test(title)) labels.add('question');
38
39 // Locale — title contains CJK (Chinese, Japanese, Korean) characters
40 if (/[぀-ヿ㐀-鿿가-힯]/.test(issue.title || '')) labels.add('lang:zh');
41
42 // Areas (path-driven hints)
43 if (/crates\/tui|\btui\b|ratatui|composer|sidebar/.test(text)) labels.add('area:tui');
44 if (/crates\/core|engine|turn ?loop|agent ?loop/.test(text)) labels.add('area:core');
45 if (/crates\/mcp|\bmcp\b/.test(text)) labels.add('area:mcp');
46 if (/crates\/state|sqlite|sessions?|persistence/.test(text)) labels.add('area:state');
47 if (/crates\/execpolicy|approval|sandbox|seatbelt|landlock/.test(text)) labels.add('area:execpolicy');
48 if (/crates\/tools|tool[ _]call|tool[ _]registry/.test(text)) labels.add('area:tools');
49 if (/install|cargo install|npm install|scoop|homebrew|prebuilt|binary/.test(text)) labels.add('area:install');
50 if (/windows/.test(text)) labels.add('os:windows');
51 if (/macos|darwin|apple silicon/.test(text)) labels.add('os:macos');
52 if (/\blinux\b|ubuntu|debian|fedora|arch ?linux/.test(text)) labels.add('os:linux');
53
54 if (labels.size === 0) return;
55
56 // Only add labels that already exist on the repo to avoid creating noise.
57 const existing = await github.paginate(github.rest.issues.listLabelsForRepo, {
58 owner: context.repo.owner,
59 repo: context.repo.repo,
60 per_page: 100,
61 });
62 const existingNames = new Set(existing.map(l => l.name));
63 const toAdd = [...labels].filter(name => existingNames.has(name));
64 if (toAdd.length === 0) return;
65
66 await github.rest.issues.addLabels({
67 owner: context.repo.owner,
68 repo: context.repo.repo,
69 issue_number: issue.number,
70 labels: toAdd,
71 });
72
72 lines YAML