返回 CodeWhale
triage.yml
根目录 / .github / workflows / triage.yml
1 name: Issue and PR triage
2
3 on:
4 issues:
5 types: [opened, reopened]
6 pull_request_target:
7 types: [opened, reopened, synchronize]
8
9 permissions:
10 issues: write
11 pull-requests: write
12 contents: read
13
14 jobs:
15 label:
16 runs-on: ubuntu-24.04
17 timeout-minutes: 10
18 steps:
19 - name: Auto-label by title, body and changed paths
20 uses: actions/github-script@v9
21 with:
22 script: |
23 const pr = context.payload.pull_request;
24 const issue = context.payload.issue || pr;
25 const title = (issue.title || '').toLowerCase();
26 const body = (issue.body || '').toLowerCase();
27 const text = `${title}\n${body}`;
28 const labels = new Set();
29
30 if (pr) {
31 const files = await github.paginate(github.rest.pulls.listFiles, {
32 owner: context.repo.owner,
33 repo: context.repo.repo,
34 pull_number: pr.number,
35 per_page: 100,
36 });
37 const pathRules = [
38 [/^crates\/(tui|tui-kit|palette)\//, 'area:tui'],
39 [/^crates\/(tools\/|engine\/src\/tools\/)/, 'area:tools'],
40 [/^crates\/(engine|core|runtime|agent|agent-contract|protocol)\/(?!src\/tools\/)/, 'area:core'],
41 [/^crates\/mcp\//, 'area:mcp'],
42 [/^crates\/(state|snapshot|memory)\//, 'area:state'],
43 [/^crates\/(sandbox|execpolicy)\//, 'area:sandbox'],
44 [/^crates\/(plugins|skills|skill-install|hooks)\//, 'area:plugins'],
45 [/^(crates\/(app-server|app-server-protocol)|npm\/runtime-sdk)\//, 'area:runtime-api'],
46 [/^crates\/models\//, 'area:providers'],
47 [/^(crates\/localization|docs\/zh_hans)\//, 'area:localization'],
48 [/^(npm\/codewhale|scripts\/release)\//, 'area:install'],
49 [/^(\.github|scripts\/ci)\//, 'area:ci'],
50 [/^apps\/desktop\//, 'area:desktop'],
51 [/^(apps\/web|web)\//, 'area:web'],
52 [/^apps\/mobile\//, 'area:mobile'],
53 ];
54 const areas = new Set();
55 let docsOnly = files.length > 0;
56 for (const f of files) {
57 if (!/^(docs\/|[^/]+\.md$)/.test(f.filename)) docsOnly = false;
58 for (const [re, name] of pathRules) if (re.test(f.filename)) areas.add(name);
59 }
60 if (areas.size <= 4) areas.forEach(name => labels.add(name));
61 if (docsOnly) labels.add('documentation');
62 if (/^feat(\(|!|:)/.test(title)) labels.add('enhancement');
63 if (/^fix(\(|!|:)/.test(title)) labels.add('bug');
64 if (/^docs(\(|!|:)/.test(title)) labels.add('documentation');
65 if (/^(chore|refactor|style|build)(\(|!|:)/.test(title)) labels.add('cleanup');
66 if (/^perf(\(|!|:)/.test(title)) labels.add('performance');
67 if (!['OWNER', 'MEMBER', 'COLLABORATOR'].includes(pr.author_association) && pr.user.type !== 'Bot') {
68 labels.add('contributor:external');
69 }
70 } else {
71
72 // Type — matched against the TITLE only.
73 //
74 // These ran against title+body and mislabelled long, well-specified
75 // issues. Any body containing an acceptance criterion like "fails
76 // when a pack drifts" matched the bug rule, and a "How to add a
77 // locale" heading matched the question rule, so planned work landed
78 // tagged `bug, question`. A title states the type; a body just
79 // discusses it. `error`/`fail` are dropped entirely — they describe
80 // what almost every issue talks about, not what any issue *is*.
81 if (/\b(bug|crash|panic|broken|stack ?trace|regression)\b/.test(title)) labels.add('bug');
82 if (/\b(feat(?:ure)?|request|enhancement|wishlist|proposal|please add|would be nice|support for)\b/.test(title)) labels.add('enhancement');
83 if (/\b(docs?|readme|documentation|typo|grammar|wording|spelling)\b/.test(title)) labels.add('documentation');
84 if (/\b(question|how (?:do|to)|why does|what does|is it possible)\b/.test(title)) labels.add('question');
85
86 // Locale — title contains CJK (Chinese, Japanese, Korean) characters
87 if (/[぀-ヿ㐀-鿿가-힯]/.test(issue.title || '')) labels.add('lang:zh');
88
89 // Areas (path-driven hints)
90 if (/crates\/tui|\btui\b|ratatui|composer|sidebar/.test(text)) labels.add('area:tui');
91 if (/crates\/core|engine|turn ?loop|agent ?loop/.test(text)) labels.add('area:core');
92 if (/crates\/mcp|\bmcp\b/.test(text)) labels.add('area:mcp');
93 if (/crates\/state|sqlite|sessions?|persistence/.test(text)) labels.add('area:state');
94 if (/crates\/execpolicy|approval|sandbox|seatbelt|landlock/.test(text)) labels.add('area:sandbox');
95 if (/crates\/tools|tool[ _]call|tool[ _]registry/.test(text)) labels.add('area:tools');
96 if (/install|cargo install|npm install|scoop|homebrew|prebuilt|binary/.test(text)) labels.add('area:install');
97 if (/\bdesktop app\b|electron/.test(text)) labels.add('area:desktop');
98 if (/app\.codewhale\.net|\bweb app\b|codewhale web/.test(text)) labels.add('area:web');
99 if (/\bmobile\b|\bios\b|\bandroid\b/.test(text)) labels.add('area:mobile');
100 if (/screen ?reader|accessib|a11y|voiceover|\bnvda\b|keyboard navigation/.test(text)) labels.add('accessibility');
101 if (/windows/.test(text)) labels.add('os:windows');
102 if (/freebsd/.test(text)) labels.add('os:freebsd');
103 if (/\bohos\b|harmonyos/.test(text)) labels.add('os:ohos');
104 if (/macos|darwin|apple silicon/.test(text)) labels.add('os:macos');
105 if (/\blinux\b|ubuntu|debian|fedora|arch ?linux/.test(text)) labels.add('os:linux');
106
107 }
108
109 if (labels.size === 0) return;
110
111 // Only add labels that already exist on the repo to avoid creating noise.
112 const existing = await github.paginate(github.rest.issues.listLabelsForRepo, {
113 owner: context.repo.owner,
114 repo: context.repo.repo,
115 per_page: 100,
116 });
117 const existingNames = new Set(existing.map(l => l.name));
118 const toAdd = [...labels].filter(name => existingNames.has(name));
119 if (toAdd.length === 0) return;
120
121 await github.rest.issues.addLabels({
122 owner: context.repo.owner,
123 repo: context.repo.repo,
124 issue_number: issue.number,
125 labels: toAdd,
126 });
127
127 lines YAML