1- name : Reopen Inactive Issues on /reopen Command
1+ name : Reopen Issue on /reopen Command
22on :
33 issue_comment :
44 types : [created]
1010 if : github.repository == 'mit-han-lab/nunchaku'
1111 runs-on : ubuntu-latest
1212 steps :
13- - name : Check if comment is /reopen by issue creator and reopen only if issue has inactive label
13+ - name : Check if comment is /reopen by issue creator and reopen
1414 uses : actions/github-script@v6
1515 with :
1616 github-token : ${{ secrets.GITHUB_TOKEN }}
@@ -20,48 +20,44 @@ jobs:
2020 const commentAuthor = context.payload.comment.user.login;
2121 const issueAuthor = context.payload.issue.user.login;
2222
23- // Get current labels on the issue
24- const labels = context.payload.issue.labels.map(label => label.name);
25-
2623 if (commentBody === '/reopen') {
2724 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- });
25+ // Only proceed if issue is currently closed
26+ if (context.payload.issue.state === 'closed') {
27+ const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
28+ try {
29+ await github.rest.issues.update({
30+ owner,
31+ repo,
32+ issue_number: issueNumber,
33+ state: 'open',
34+ });
3935
40- // Remove 'inactive' label
36+ // Remove 'inactive' label if present
37+ const labels = context.payload.issue.labels.map(label => label.name);
38+ if (labels.includes('inactive')) {
4139 const newLabels = labels.filter(label => label !== 'inactive');
4240 await github.rest.issues.update({
4341 owner,
4442 repo,
4543 issue_number: issueNumber,
4644 labels: newLabels,
4745 });
46+ }
4847
49- await github.rest.issues.createComment({
50- owner,
51- repo,
52- issue_number: issueNumber,
53- body: `Issue reopened by @${commentAuthor} via \`/reopen\` command.`,
54- });
48+ await github.rest.issues.createComment({
49+ owner,
50+ repo,
51+ issue_number: issueNumber,
52+ body: `Issue reopened by @${commentAuthor} via \`/reopen\` command.`,
53+ });
5554
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.`);
55+ console.log(`Reopened issue #${issueNumber} by request of issuer.`);
56+ } catch (error) {
57+ console.error(`Failed to reopen issue #${issueNumber}: ${error.message}`);
6258 }
6359 } else {
64- console.log(`Issue #${issueNumber} does not have 'inactive' label, skipping .`);
60+ console.log(`Issue #${issueNumber} is already open .`);
6561 }
6662 } else {
6763 console.log(`Commenter @${commentAuthor} is not the issue creator @${issueAuthor}, ignoring.`);
0 commit comments