Assign or unassign "stale" on comments #1163
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Assign or unassign "stale" on comments | |
| on: | |
| issue_comment: | |
| types: [created] | |
| permissions: | |
| issues: write | |
| repository-projects: read | |
| pull-requests: read | |
| jobs: | |
| help_unhelp: | |
| runs-on: ubuntu-latest | |
| if: github.event.issue.pull_request == null | |
| steps: | |
| - name: Check comment and label accordingly | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const comment = context.payload.comment.body.trim().toLowerCase(); | |
| const commentId = context.payload.comment.id; | |
| const issueNumber = context.payload.issue.number; | |
| const label = "stale"; | |
| async function deleteComment() { | |
| await github.rest.issues.deleteComment({ | |
| ...context.repo, | |
| comment_id: commentId | |
| }); | |
| console.log(`Deleted comment ID ${commentId}`); | |
| } | |
| if (comment.startsWith("/stale")) { | |
| await github.rest.issues.addLabels({ | |
| ...context.repo, | |
| issue_number: issueNumber, | |
| labels: [label] | |
| }); | |
| console.log(`Added 'help needed' label to issue #${issueNumber}`); | |
| await deleteComment(); | |
| } else if (comment.startsWith("/unstale")) { | |
| try { | |
| await github.rest.issues.removeLabel({ | |
| ...context.repo, | |
| issue_number: issueNumber, | |
| name: label | |
| }); | |
| console.log(`Removed 'help needed' label from issue #${issueNumber}`); | |
| } catch (error) { | |
| if (error.status === 404) { | |
| console.log(`Label not found on issue #${issueNumber}`); | |
| } else { | |
| throw error; | |
| } | |
| } | |
| await deleteComment(); | |
| } |