1name: Bot - PR Approval Command
2
3on:
4 issue_comment:
5 types: [created]
6
7jobs:
8 approve:
9 if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '/approve') }}
10 runs-on: ubuntu-latest
11 steps:
12 - name: Process Approval Command
13 uses: actions/github-script@v9
14 with:
15 github-token: ${{ secrets.HOMEBREW_GITHUB_TOKEN }}
16 script: |
17 const commenter = context.payload.comment.user.login;
18 const owner = context.repo.owner;
19 const repo = context.repo.repo;
20 const pr_number = context.issue.number;
21
22 try {
23 // 1. Verify membership in the floatpane organization
24 await github.rest.orgs.checkMembershipForUser({
25 org: 'floatpane',
26 username: commenter,
27 });
28
29 // 2. Add an approving review
30 await github.rest.pulls.createReview({
31 owner,
32 repo,
33 pull_number: pr_number,
34 event: 'APPROVE',
35 body: `Approved on behalf of @${commenter} via \`/approve\` command.`
36 });
37
38 // Optionally add a reaction to the command comment to acknowledge it
39 await github.rest.reactions.createForIssueComment({
40 owner,
41 repo,
42 comment_id: context.payload.comment.id,
43 content: 'rocket'
44 });
45
46 } catch (error) {
47 if (error.status === 404) {
48 // Not a member
49 await github.rest.issues.createComment({
50 owner, repo, issue_number: pr_number,
51 body: `Sorry @${commenter}, only members of the \`floatpane\` organization can use the \`/approve\` command.`
52 });
53 } else {
54 core.setFailed(`Error processing approval: ${error.message}`);
55 }
56 }