|
| 1 | +name: Reopen Issue 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/ComfyUI-nunchaku' |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Check if comment is /reopen by issue creator and reopen |
| 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 | + if (commentBody === '/reopen') { |
| 24 | + if (commentAuthor === issueAuthor) { |
| 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 | + }); |
| 35 | +
|
| 36 | + // Remove 'inactive' label if present |
| 37 | + const labels = context.payload.issue.labels.map(label => label.name); |
| 38 | + if (labels.includes('inactive')) { |
| 39 | + const newLabels = labels.filter(label => label !== 'inactive'); |
| 40 | + await github.rest.issues.update({ |
| 41 | + owner, |
| 42 | + repo, |
| 43 | + issue_number: issueNumber, |
| 44 | + labels: newLabels, |
| 45 | + }); |
| 46 | + } |
| 47 | +
|
| 48 | + await github.rest.issues.createComment({ |
| 49 | + owner, |
| 50 | + repo, |
| 51 | + issue_number: issueNumber, |
| 52 | + body: `Issue reopened by @${commentAuthor} via \`/reopen\` command.`, |
| 53 | + }); |
| 54 | +
|
| 55 | + console.log(`Reopened issue #${issueNumber} by request of issuer.`); |
| 56 | + } catch (error) { |
| 57 | + console.error(`Failed to reopen issue #${issueNumber}: ${error.message}`); |
| 58 | + } |
| 59 | + } else { |
| 60 | + console.log(`Issue #${issueNumber} is already open.`); |
| 61 | + } |
| 62 | + } else { |
| 63 | + console.log(`Commenter @${commentAuthor} is not the issue creator @${issueAuthor}, ignoring.`); |
| 64 | + } |
| 65 | + } else { |
| 66 | + console.log(`Comment is not /reopen, ignoring.`); |
| 67 | + } |
0 commit comments