Check/remove status labels from closed issues #2
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: Remove label from closed issues | |
on: | |
issues: | |
types: | |
- closed | |
jobs: | |
label_issues: | |
runs-on: ubuntu-latest | |
permissions: | |
issues: write | |
steps: | |
- uses: actions/github-script@v7 | |
with: | |
script: | | |
console.log(context.issue); | |
const originalLabels = context.issue.labels.map(l => l.name); | |
console.log(originalLabels); | |
const newLabels = originalLabels.filter(l => l !== "status: in progress" && l !== "status: new"); | |
console.log(newLabels); | |
if (newLabels.length !== originalLabels.length) { | |
github.rest.issues.update({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
labels: newLabels, | |
}); | |
} | |
const statusLabels = newLabels.filter(l => l.startsWith("status: ")); | |
console.log(statusLabels); | |
if (context.issue.state_reason === "not planned" && statusLabels.length === 0) { | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: "Please assign a status label to this issue.", | |
}); | |
github.rest.issues.update({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: "open", | |
}); | |
} |