Add workflow to remove labels when an issue gets closed (#7910)

This commit is contained in:
Keunes 2025-08-02 17:16:39 +02:00 committed by GitHub
parent 705be4814d
commit 5e1ec5fc2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 52 additions and 2 deletions

View File

@ -11,7 +11,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v5
- uses: actions/stale@v9
with:
days-before-stale: 7
days-before-close: 7
@ -20,7 +20,7 @@ jobs:
stale-pr-label: 'Needs: Reply still'
stale-issue-message: "This issue will be closed when we don't get a reply within 7 days."
stale-pr-message: "This PR will be closed when we don't get a reply within 7 days."
labels-to-remove-when-unstale: 'Needs: Reply'
labels-to-remove-when-stale: 'Needs: Reply'
close-issue-label: "Close reason: No reply"
close-pr-label: "Close reason: No reply"
close-issue-message: "This issue was closed because we didn't get a reply for 14 days."

View File

@ -0,0 +1,50 @@
name: Remove labels when issue gets closed
on:
issues:
types: [closed]
jobs:
remove-labels:
runs-on: ubuntu-latest
steps:
- name: Remove labels from closed issue
uses: actions/github-script@v7
with:
script: |
const labelsToRemove = ['Needs: Triage', 'Needs: Decision', 'Needs: Reply still'];
const issue = context.payload.issue;
// Get current labels on the issue
const currentLabels = issue.labels.map(label => label.name);
// Create updated label list by filtering out the labels to remove
const updatedLabels = currentLabels.filter(label =>
!labelsToRemove.includes(label)
);
// Check if any labels were actually removed
const removedLabels = currentLabels.filter(label =>
labelsToRemove.includes(label)
);
if (removedLabels.length > 0) {
console.log(`Removing labels: ${removedLabels.join(', ')}`);
console.log(`Updated label list: ${updatedLabels.join(', ') || 'No labels remaining'}`);
try {
// Update the issue with the new label list in a single operation
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: updatedLabels
});
console.log(`Successfully updated labels. Removed: ${removedLabels.join(', ')}`);
} catch (error) {
console.log(`Failed to update labels: ${error.message}`);
}
} else {
console.log('No target labels found on this issue to remove.');
}