| 1 | name: Issue Labels |
| 2 | |
| 3 | on: |
| 4 | push: |
| 5 | branches: |
| 6 | - main |
| 7 | paths: |
| 8 | - .github/ISSUE_TEMPLATE/** |
| 9 | - .github/workflows/issue-labels.yml |
| 10 | workflow_dispatch: |
| 11 | |
| 12 | permissions: |
| 13 | issues: write |
| 14 | |
| 15 | jobs: |
| 16 | sync: |
| 17 | name: Sync issue labels |
| 18 | runs-on: ubuntu-24.04 |
| 19 | steps: |
| 20 | - name: Ensure managed issue labels exist |
| 21 | uses: actions/github-script@v7 |
| 22 | with: |
| 23 | script: | |
| 24 | const managedLabels = [ |
| 25 | { |
| 26 | name: "bug", |
| 27 | color: "d73a4a", |
| 28 | description: "Something is broken or behaving incorrectly.", |
| 29 | }, |
| 30 | { |
| 31 | name: "enhancement", |
| 32 | color: "a2eeef", |
| 33 | description: "Requested improvement or new capability.", |
| 34 | }, |
| 35 | { |
| 36 | name: "needs-triage", |
| 37 | color: "fbca04", |
| 38 | description: "Issue needs maintainer review and initial categorization.", |
| 39 | }, |
| 40 | ]; |
| 41 | |
| 42 | for (const label of managedLabels) { |
| 43 | try { |
| 44 | const { data: existing } = await github.rest.issues.getLabel({ |
| 45 | owner: context.repo.owner, |
| 46 | repo: context.repo.repo, |
| 47 | name: label.name, |
| 48 | }); |
| 49 | |
| 50 | if ( |
| 51 | existing.color !== label.color || |
| 52 | (existing.description ?? "") !== label.description |
| 53 | ) { |
| 54 | await github.rest.issues.updateLabel({ |
| 55 | owner: context.repo.owner, |
| 56 | repo: context.repo.repo, |
| 57 | name: label.name, |
| 58 | color: label.color, |
| 59 | description: label.description, |
| 60 | }); |
| 61 | } |
| 62 | } catch (error) { |
| 63 | if (error.status !== 404) { |
| 64 | throw error; |
| 65 | } |
| 66 | |
| 67 | await github.rest.issues.createLabel({ |
| 68 | owner: context.repo.owner, |
| 69 | repo: context.repo.repo, |
| 70 | name: label.name, |
| 71 | color: label.color, |
| 72 | description: label.description, |
| 73 | }); |
| 74 | } |
| 75 | } |