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