| 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@v7 |
| 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 |
| 26 | if (/\b(bug|crash|panic|broken|stack ?trace|regression|err(?:or)?|fail(?:ed|ure)?)\b/.test(text)) labels.add('bug'); |
| 27 | if (/\b(feat(?:ure)?|request|enhancement|wishlist|proposal|please add|would be nice|support for)\b/.test(text)) labels.add('enhancement'); |
| 28 | if (/\b(docs?|readme|documentation|typo|grammar|wording|spelling)\b/.test(text)) labels.add('documentation'); |
| 29 | if (/\b(question|how (?:do|to)|why does|what does|is it possible)\b/.test(text)) labels.add('question'); |
| 30 | |
| 31 | // Locale — title contains CJK (Chinese, Japanese, Korean) characters |
| 32 | if (/[-ヿ㐀-鿿가-]/.test(issue.title || '')) labels.add('lang:zh'); |
| 33 | |
| 34 | // Areas (path-driven hints) |
| 35 | if (/crates\/tui|\btui\b|ratatui|composer|sidebar/.test(text)) labels.add('area:tui'); |
| 36 | if (/crates\/core|engine|turn ?loop|agent ?loop/.test(text)) labels.add('area:core'); |
| 37 | if (/crates\/mcp|\bmcp\b/.test(text)) labels.add('area:mcp'); |
| 38 | if (/crates\/state|sqlite|sessions?|persistence/.test(text)) labels.add('area:state'); |
| 39 | if (/crates\/execpolicy|approval|sandbox|seatbelt|landlock/.test(text)) labels.add('area:execpolicy'); |
| 40 | if (/crates\/tools|tool[ _]call|tool[ _]registry/.test(text)) labels.add('area:tools'); |
| 41 | if (/install|cargo install|npm install|scoop|homebrew|prebuilt|binary/.test(text)) labels.add('area:install'); |
| 42 | if (/windows/.test(text)) labels.add('os:windows'); |
| 43 | if (/macos|darwin|apple silicon/.test(text)) labels.add('os:macos'); |
| 44 | if (/\blinux\b|ubuntu|debian|fedora|arch ?linux/.test(text)) labels.add('os:linux'); |
| 45 | |
| 46 | if (labels.size === 0) return; |
| 47 | |
| 48 | // Only add labels that already exist on the repo to avoid creating noise. |
| 49 | const existing = await github.paginate(github.rest.issues.listLabelsForRepo, { |
| 50 | owner: context.repo.owner, |
| 51 | repo: context.repo.repo, |
| 52 | per_page: 100, |
| 53 | }); |
| 54 | const existingNames = new Set(existing.map(l => l.name)); |
| 55 | const toAdd = [...labels].filter(name => existingNames.has(name)); |
| 56 | if (toAdd.length === 0) return; |
| 57 | |
| 58 | await github.rest.issues.addLabels({ |
| 59 | owner: context.repo.owner, |
| 60 | repo: context.repo.repo, |
| 61 | issue_number: issue.number, |
| 62 | labels: toAdd, |
| 63 | }); |
| 64 |