ci(issues): testing issue labeling automation pipeline #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Issues | |
on: | |
issues: | |
types: | |
- opened | |
- reopened | |
- closed | |
jobs: | |
label_issues: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Remove existing 'state:' labels | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const issueNumber = context.issue.number; | |
const { data: labels } = await github.issues.listLabelsOnIssue({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issueNumber, | |
}); | |
for (const label of labels) { | |
if (label.name.startsWith('state:')) { | |
await github.issues.removeLabel({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issueNumber, | |
name: label.name, | |
}); | |
} | |
} | |
- name: Add 'state:Backlog' label on issue opened or reopened | |
if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' }} | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const labelName = 'state:Backlog'; | |
const { data: allLabels } = await github.issues.listLabelsForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
if (allLabels.some(label => label.name === labelName)) { | |
await github.issues.addLabels({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
labels: [labelName], | |
}); | |
} | |
- name: Add 'state:Done' label on issue closed | |
if: ${{ github.event.action == 'closed' }} | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const labelName = 'state:Done'; | |
const { data: allLabels } = await github.issues.listLabelsForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
if (allLabels.some(label => label.name === labelName)) { | |
await github.issues.addLabels({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
labels: [labelName], | |
}); | |
} |