Skip to content

Commit 35aab2f

Browse files
committed
chore: add a workflow to reopen the inactive issues
1 parent ed451a8 commit 35aab2f

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

.github/workflows/close-inactive-issues.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
owner,
7070
repo,
7171
issue_number: issue.number,
72-
body: 'This issue has been automatically closed due to 30-day inactivity. Please feel free to reopen it if needed.'
72+
body: 'This issue has been automatically closed due to 30-day inactivity. Please feel free to reopen it with `/reopen` if needed.'
7373
});
7474
console.log(`Closed issue #${issue.number} due to inactivity.`);
7575
} catch (error) {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Reopen Inactive Issues on /reopen Command
2+
on:
3+
issue_comment:
4+
types: [created]
5+
permissions:
6+
issues: write
7+
contents: read
8+
jobs:
9+
reopen-issue:
10+
if: github.repository == 'mit-han-lab/nunchaku'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check if comment is /reopen by issue creator and reopen only if issue has inactive label
14+
uses: actions/github-script@v6
15+
with:
16+
github-token: ${{ secrets.GITHUB_TOKEN }}
17+
script: |
18+
const commentBody = context.payload.comment.body.trim();
19+
const issueNumber = context.payload.issue.number;
20+
const commentAuthor = context.payload.comment.user.login;
21+
const issueAuthor = context.payload.issue.user.login;
22+
23+
// Get current labels on the issue
24+
const labels = context.payload.issue.labels.map(label => label.name);
25+
26+
if (commentBody === '/reopen') {
27+
if (commentAuthor === issueAuthor) {
28+
if (labels.includes('inactive')) {
29+
if (context.payload.issue.state === 'closed') {
30+
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
31+
try {
32+
// Reopen the issue
33+
await github.rest.issues.update({
34+
owner,
35+
repo,
36+
issue_number: issueNumber,
37+
state: 'open',
38+
});
39+
40+
// Remove 'inactive' label
41+
const newLabels = labels.filter(label => label !== 'inactive');
42+
await github.rest.issues.update({
43+
owner,
44+
repo,
45+
issue_number: issueNumber,
46+
labels: newLabels,
47+
});
48+
49+
await github.rest.issues.createComment({
50+
owner,
51+
repo,
52+
issue_number: issueNumber,
53+
body: `Issue reopened by @${commentAuthor} via /reopen command.`,
54+
});
55+
56+
console.log(`Reopened issue #${issueNumber} with 'inactive' label by issuer.`);
57+
} catch (error) {
58+
console.error(`Failed to reopen issue #${issueNumber}: ${error.message}`);
59+
}
60+
} else {
61+
console.log(`Issue #${issueNumber} is already open.`);
62+
}
63+
} else {
64+
console.log(`Issue #${issueNumber} does not have 'inactive' label, skipping.`);
65+
}
66+
} else {
67+
console.log(`Commenter @${commentAuthor} is not the issue creator @${issueAuthor}, ignoring.`);
68+
}
69+
} else {
70+
console.log(`Comment is not /reopen, ignoring.`);
71+
}

0 commit comments

Comments
 (0)