Skip to content

Check/remove status labels from closed issues #2

Check/remove status labels from closed issues

Check/remove status labels from closed issues #2

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",
});
}