Commit 189be8bf authored by Muyang Li's avatar Muyang Li
Browse files

[Auto Merge] chore: /reopen can be used in any issue

parents c80de1e6 2a785f77
name: Reopen Inactive Issues on /reopen Command name: Reopen Issue on /reopen Command
on: on:
issue_comment: issue_comment:
types: [created] types: [created]
...@@ -10,7 +10,7 @@ jobs: ...@@ -10,7 +10,7 @@ jobs:
if: github.repository == 'mit-han-lab/nunchaku' if: github.repository == 'mit-han-lab/nunchaku'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check if comment is /reopen by issue creator and reopen only if issue has inactive label - name: Check if comment is /reopen by issue creator and reopen
uses: actions/github-script@v6 uses: actions/github-script@v6
with: with:
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
...@@ -20,24 +20,22 @@ jobs: ...@@ -20,24 +20,22 @@ jobs:
const commentAuthor = context.payload.comment.user.login; const commentAuthor = context.payload.comment.user.login;
const issueAuthor = context.payload.issue.user.login; const issueAuthor = context.payload.issue.user.login;
// Get current labels on the issue
const labels = context.payload.issue.labels.map(label => label.name);
if (commentBody === '/reopen') { if (commentBody === '/reopen') {
if (commentAuthor === issueAuthor) { if (commentAuthor === issueAuthor) {
if (labels.includes('inactive')) { // Only proceed if issue is currently closed
if (context.payload.issue.state === 'closed') { if (context.payload.issue.state === 'closed') {
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/'); const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
try { try {
// Reopen the issue await github.rest.issues.update({
await github.rest.issues.update({ owner,
owner, repo,
repo, issue_number: issueNumber,
issue_number: issueNumber, state: 'open',
state: 'open', });
});
// Remove 'inactive' label // Remove 'inactive' label if present
const labels = context.payload.issue.labels.map(label => label.name);
if (labels.includes('inactive')) {
const newLabels = labels.filter(label => label !== 'inactive'); const newLabels = labels.filter(label => label !== 'inactive');
await github.rest.issues.update({ await github.rest.issues.update({
owner, owner,
...@@ -45,23 +43,21 @@ jobs: ...@@ -45,23 +43,21 @@ jobs:
issue_number: issueNumber, issue_number: issueNumber,
labels: newLabels, labels: newLabels,
}); });
}
await github.rest.issues.createComment({ await github.rest.issues.createComment({
owner, owner,
repo, repo,
issue_number: issueNumber, issue_number: issueNumber,
body: `Issue reopened by @${commentAuthor} via \`/reopen\` command.`, body: `Issue reopened by @${commentAuthor} via \`/reopen\` command.`,
}); });
console.log(`Reopened issue #${issueNumber} with 'inactive' label by issuer.`); console.log(`Reopened issue #${issueNumber} by request of issuer.`);
} catch (error) { } catch (error) {
console.error(`Failed to reopen issue #${issueNumber}: ${error.message}`); console.error(`Failed to reopen issue #${issueNumber}: ${error.message}`);
}
} else {
console.log(`Issue #${issueNumber} is already open.`);
} }
} else { } else {
console.log(`Issue #${issueNumber} does not have 'inactive' label, skipping.`); console.log(`Issue #${issueNumber} is already open.`);
} }
} else { } else {
console.log(`Commenter @${commentAuthor} is not the issue creator @${issueAuthor}, ignoring.`); console.log(`Commenter @${commentAuthor} is not the issue creator @${issueAuthor}, ignoring.`);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment