|
| 1 | +name: Issues |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - reopened |
| 8 | + - closed |
| 9 | + |
| 10 | +jobs: |
| 11 | + label_issues: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Remove existing 'state:' labels |
| 15 | + uses: actions/github-script@v6 |
| 16 | + with: |
| 17 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 18 | + script: | |
| 19 | + const issueNumber = context.issue.number; |
| 20 | +
|
| 21 | + // Get current labels of the issue |
| 22 | + const { data: labels } = await octokit.issues.listLabelsOnIssue({ |
| 23 | + owner: context.repo.owner, |
| 24 | + repo: context.repo.repo, |
| 25 | + issue_number: issueNumber, |
| 26 | + }); |
| 27 | +
|
| 28 | + // Remove labels that start with 'state:' |
| 29 | + for (const label of labels) { |
| 30 | + if (label.name.startsWith('state:')) { |
| 31 | + await octokit.issues.removeLabel({ |
| 32 | + owner: context.repo.owner, |
| 33 | + repo: context.repo.repo, |
| 34 | + issue_number: issueNumber, |
| 35 | + name: label.name, |
| 36 | + }); |
| 37 | + } |
| 38 | + } |
| 39 | +
|
| 40 | + - name: Add 'state:Backlog' label on issue opened or reopened |
| 41 | + if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' }} |
| 42 | + uses: actions/github-script@v6 |
| 43 | + with: |
| 44 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + script: | |
| 46 | + const labelName = 'state:Backlog'; |
| 47 | + const { data: allLabels } = await octokit.issues.listLabelsForRepo({ |
| 48 | + owner: context.repo.owner, |
| 49 | + repo: context.repo.repo, |
| 50 | + }); |
| 51 | +
|
| 52 | + // Check if the label exists |
| 53 | + if (allLabels.some(label => label.name === labelName)) { |
| 54 | + await octokit.issues.addLabels({ |
| 55 | + owner: context.repo.owner, |
| 56 | + repo: context.repo.repo, |
| 57 | + issue_number: context.issue.number, |
| 58 | + labels: [labelName], |
| 59 | + }); |
| 60 | + } |
| 61 | +
|
| 62 | + - name: Add 'state:Done' label on issue closed |
| 63 | + if: ${{ github.event.action == 'closed' }} |
| 64 | + uses: actions/github-script@v6 |
| 65 | + with: |
| 66 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + script: | |
| 68 | + const labelName = 'state:Done'; |
| 69 | + const { data: allLabels } = await octokit.issues.listLabelsForRepo({ |
| 70 | + owner: context.repo.owner, |
| 71 | + repo: context.repo.repo, |
| 72 | + }); |
| 73 | +
|
| 74 | + // Check if the label exists |
| 75 | + if (allLabels.some(label => label.name === labelName)) { |
| 76 | + await octokit.issues.addLabels({ |
| 77 | + owner: context.repo.owner, |
| 78 | + repo: context.repo.repo, |
| 79 | + issue_number: context.issue.number, |
| 80 | + labels: [labelName], |
| 81 | + }); |
| 82 | + } |
0 commit comments