Bot - PR Approval Command #6
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: Bot - PR Approval Command | |
| on: | |
| issue_comment: | |
| types: [created] | |
| jobs: | |
| approve: | |
| if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '/approve') }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Process Approval Command | |
| uses: actions/github-script@v9 | |
| with: | |
| github-token: ${{ secrets.BOT_GITHUB_TOKEN }} | |
| script: | | |
| const commenter = context.payload.comment.user.login; | |
| const owner = context.repo.owner; | |
| const repo = context.repo.repo; | |
| const pr_number = context.issue.number; | |
| try { | |
| await github.rest.orgs.checkMembershipForUser({ | |
| org: 'floatpane', | |
| username: commenter, | |
| }); | |
| await github.rest.pulls.createReview({ | |
| owner, | |
| repo, | |
| pull_number: pr_number, | |
| event: 'APPROVE', | |
| body: `Approved on behalf of @${commenter} via \`/approve\` command.` | |
| }); | |
| await github.rest.reactions.createForIssueComment({ | |
| owner, | |
| repo, | |
| comment_id: context.payload.comment.id, | |
| content: 'rocket' | |
| }); | |
| } catch (error) { | |
| if (error.status === 404) { | |
| await github.rest.issues.createComment({ | |
| owner, repo, issue_number: pr_number, | |
| body: `Sorry @${commenter}, only members of the \`floatpane\` organization can use the \`/approve\` command.` | |
| }); | |
| } else { | |
| core.setFailed(`Error processing approval: ${error.message}`); | |
| } | |
| } |