|
| 1 | +# SPDX-FileCopyrightText: 2025 Intel Corporation |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +name: Auto Label on Issue Events |
| 8 | + |
| 9 | +on: |
| 10 | + workflow_dispatch: |
| 11 | + issues: |
| 12 | + types: [assigned, closed] |
| 13 | + |
| 14 | +permissions: |
| 15 | + issues: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + label-on-close: |
| 19 | + if: github.event.action == 'closed' |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - name: Add 'Closed' label when issue is closed |
| 23 | + uses: actions/github-script@v8 |
| 24 | + with: |
| 25 | + script: | |
| 26 | + await github.rest.issues.addLabels({ |
| 27 | + issue_number: context.issue.number, |
| 28 | + owner: context.repo.owner, |
| 29 | + repo: context.repo.repo, |
| 30 | + labels: ['Closed'] |
| 31 | + }); |
| 32 | +
|
| 33 | + - name: Remove 'triage', 'investigating', and 'in progress' labels if present (on close) |
| 34 | + uses: actions/github-script@v8 |
| 35 | + with: |
| 36 | + script: | |
| 37 | + const labelsToRemove = ['triage', 'investigating', 'in progress']; |
| 38 | + const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({ |
| 39 | + owner: context.repo.owner, |
| 40 | + repo: context.repo.repo, |
| 41 | + issue_number: context.issue.number, |
| 42 | + }); |
| 43 | + for (const l of currentLabels) { |
| 44 | + if (labelsToRemove.includes(l.name)) { |
| 45 | + await github.rest.issues.removeLabel({ |
| 46 | + owner: context.repo.owner, |
| 47 | + repo: context.repo.repo, |
| 48 | + issue_number: context.issue.number, |
| 49 | + name: l.name, |
| 50 | + }); |
| 51 | + } |
| 52 | + } |
| 53 | +
|
| 54 | + label-on-assigned: |
| 55 | + if: github.event.action == 'assigned' |
| 56 | + runs-on: ubuntu-latest |
| 57 | + steps: |
| 58 | + - name: Add 'investigating' label when issue is assigned |
| 59 | + uses: actions/github-script@v8 |
| 60 | + with: |
| 61 | + script: | |
| 62 | + // Add the 'investigating' label if not already present |
| 63 | + const current = (await github.rest.issues.listLabelsOnIssue({ |
| 64 | + issue_number: context.issue.number, |
| 65 | + owner: context.repo.owner, |
| 66 | + repo: context.repo.repo |
| 67 | + })).data.map(l => l.name); |
| 68 | + if (!current.includes('investigating')) { |
| 69 | + await github.rest.issues.addLabels({ |
| 70 | + issue_number: context.issue.number, |
| 71 | + owner: context.repo.owner, |
| 72 | + repo: context.repo.repo, |
| 73 | + labels: ['investigating'] |
| 74 | + }); |
| 75 | + } |
| 76 | +
|
| 77 | + - name: Remove 'triage' label if present (on assign) |
| 78 | + uses: actions/github-script@v8 |
| 79 | + with: |
| 80 | + script: | |
| 81 | + const labels = (await github.rest.issues.listLabelsOnIssue({ |
| 82 | + issue_number: context.issue.number, |
| 83 | + owner: context.repo.owner, |
| 84 | + repo: context.repo.repo |
| 85 | + })).data.map(label => label.name); |
| 86 | + if (labels.includes('triage')) { |
| 87 | + await github.rest.issues.removeLabel({ |
| 88 | + issue_number: context.issue.number, |
| 89 | + owner: context.repo.owner, |
| 90 | + repo: context.repo.repo, |
| 91 | + name: 'triage' |
| 92 | + }); |
| 93 | + } |
0 commit comments