Comment Commands #280
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: Comment Commands | |
| on: issue_comment | |
| jobs: | |
| points: | |
| runs-on: ubuntu-20.04 | |
| if: startsWith(github.event.comment.body, '/points') | |
| steps: | |
| - name: Extract Command | |
| id: command | |
| uses: xt0rted/slash-command-action@v1 | |
| with: | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| command: points | |
| reaction: "true" | |
| reaction-type: "eyes" | |
| allow-edits: "false" | |
| permission-level: write | |
| - name: Handle Command | |
| uses: actions/github-script@v4 | |
| env: | |
| POINTS: ${{ steps.command.outputs.command-arguments }} | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const points = process.env.POINTS | |
| if (isNaN(parseInt(points))) { | |
| console.log("Malformed command - expected '/points <int>'") | |
| github.reactions.createForIssueComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: context.payload.comment.id, | |
| content: "confused" | |
| }) | |
| return | |
| } | |
| const label = "points/" + points | |
| // Delete our needs-points-label label. | |
| try { | |
| await github.issues.deleteLabel({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| name: ['needs-points-label'] | |
| }) | |
| console.log("Deleted 'needs-points-label' label.") | |
| } | |
| catch(e) { | |
| console.log("Label 'needs-points-label' probably didn't exist.") | |
| } | |
| // Add our points label. | |
| github.issues.addLabels({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| labels: [label] | |
| }) | |
| console.log("Added '" + label + "' label.") |