-
-
Notifications
You must be signed in to change notification settings - Fork 66
56 lines (50 loc) · 1.93 KB
/
bot-approve.yml
File metadata and controls
56 lines (50 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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.HOMEBREW_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 {
// 1. Verify membership in the floatpane organization
await github.rest.orgs.checkMembershipForUser({
org: 'floatpane',
username: commenter,
});
// 2. Add an approving review
await github.rest.pulls.createReview({
owner,
repo,
pull_number: pr_number,
event: 'APPROVE',
body: `Approved on behalf of @${commenter} via \`/approve\` command.`
});
// Optionally add a reaction to the command comment to acknowledge it
await github.rest.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: 'rocket'
});
} catch (error) {
if (error.status === 404) {
// Not a member
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}`);
}
}