Skip to content

Commit 7948a03

Browse files
committed
Feat: remove labels and assignees on issue close
1 parent 47277a6 commit 7948a03

File tree

2 files changed

+57
-38
lines changed

2 files changed

+57
-38
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Remove Labels and Assignees on Issue Close
2+
3+
on:
4+
issues:
5+
types: [closed]
6+
pull_request:
7+
types: [closed]
8+
9+
jobs:
10+
remove-labels-and-assignees:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Remove labels and assignees
14+
uses: actions/github-script@v7
15+
with:
16+
github-token: ${{ secrets.GITHUB_TOKEN }}
17+
script: |
18+
const issue = context.payload.issue || context.payload.pull_request;
19+
const { owner, repo } = context.repo;
20+
21+
try {
22+
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
23+
owner,
24+
repo,
25+
issue_number: issue.number
26+
});
27+
28+
const labelsToKeep = currentLabels
29+
.filter(label => label.name === '⏱︎ Stale')
30+
.map(label => label.name);
31+
32+
await github.rest.issues.setLabels({
33+
owner,
34+
repo,
35+
issue_number: issue.number,
36+
labels: labelsToKeep
37+
});
38+
} catch (error) {
39+
if (error.status !== 404) {
40+
throw error;
41+
}
42+
}
43+
44+
if (issue.assignees && issue.assignees.length > 0) {
45+
try {
46+
await github.rest.issues.removeAssignees({
47+
owner,
48+
repo,
49+
issue_number: issue.number,
50+
assignees: issue.assignees.map(assignee => assignee.login)
51+
});
52+
} catch (error) {
53+
if (error.status !== 404) {
54+
throw error;
55+
}
56+
}
57+
}

.github/workflows/remove-labels-assignees-on-close.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)