|
| 1 | +name: Label issue areas |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - edited |
| 8 | + - reopened |
| 9 | + |
| 10 | +permissions: |
| 11 | + issues: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + label-area: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Apply area label |
| 18 | + uses: actions/github-script@v7 |
| 19 | + with: |
| 20 | + script: | |
| 21 | + const body = context.payload.issue.body ?? ''; |
| 22 | + const match = body.match(/### Area[\s\S]*?\n\n([^\n]+)/); |
| 23 | + if (!match) { |
| 24 | + core.info('No area field found.'); |
| 25 | + return; |
| 26 | + } |
| 27 | +
|
| 28 | + const area = match[1].trim(); |
| 29 | + const areaLabels = new Map([ |
| 30 | + ['VSCode extension', 'vscode'], |
| 31 | + ['Language server', 'language-server'], |
| 32 | + ['Debugger', 'debugger'], |
| 33 | + ['Documentation', 'documentation'], |
| 34 | + ['Other', 'other'], |
| 35 | + ]); |
| 36 | +
|
| 37 | + const desiredLabel = areaLabels.get(area); |
| 38 | + if (!desiredLabel) { |
| 39 | + core.info(`No label mapping for area: ${area}`); |
| 40 | + return; |
| 41 | + } |
| 42 | +
|
| 43 | + const knownAreaLabels = [...areaLabels.values()]; |
| 44 | + const existingLabels = await github.paginate(github.rest.issues.listLabelsOnIssue, { |
| 45 | + owner: context.repo.owner, |
| 46 | + repo: context.repo.repo, |
| 47 | + issue_number: context.issue.number, |
| 48 | + per_page: 100, |
| 49 | + }); |
| 50 | +
|
| 51 | + for (const label of existingLabels) { |
| 52 | + if (knownAreaLabels.includes(label.name) && label.name !== desiredLabel) { |
| 53 | + await github.rest.issues.removeLabel({ |
| 54 | + owner: context.repo.owner, |
| 55 | + repo: context.repo.repo, |
| 56 | + issue_number: context.issue.number, |
| 57 | + name: label.name, |
| 58 | + }); |
| 59 | + } |
| 60 | + } |
| 61 | +
|
| 62 | + await github.rest.issues.addLabels({ |
| 63 | + owner: context.repo.owner, |
| 64 | + repo: context.repo.repo, |
| 65 | + issue_number: context.issue.number, |
| 66 | + labels: [desiredLabel], |
| 67 | + }); |
0 commit comments