-
Notifications
You must be signed in to change notification settings - Fork 2
73 lines (61 loc) · 2.17 KB
/
cookbook_pr_trigger.yaml
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Trigger preproc on comment with "/regenerate-cache"
on:
issue_comment:
types: [created]
jobs:
trigger:
if: ${{ github.event.issue.pull_request }}
runs-on: ubuntu-latest
steps:
- name: Dispatch preproc
if: ${{ github.event.issue.pull_request }}
uses: actions/github-script@v6
with:
script: |
const owner = context.repo.owner
const repo = context.repo.repo
const pr_number = context.issue.number
const comment = context.payload.comment
// Return early if comment is not the trigger phrase
if (comment.body != '/regenerate-cache') {
console.log("Comment is not trigger phrase")
return
}
const commenter = await github.request(
'GET /repos/{owner}/{repo}/collaborators/{username}/permission',
{
owner: owner,
repo: repo,
username: comment.user.login,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
},
)
const commenter_can_push = commenter.data.user.permissions.push
// Return early if comment sender doesn't have push rights
if (!commenter_can_push) {
console.log("User does not have push permissions")
return
}
const pr = await github.rest.pulls.get({
pull_number: pr_number,
owner: owner,
repo: repo,
})
const ref = pr.data.head.ref
// We didn't return early, so dispatch the workflow
const dispatch = await github.request(
'POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches',
{
owner: owner,
repo: repo,
workflow_id: 'cookbook_preproc.yaml',
ref: ref,
inputs: {pr_number: pr_number.toString()},
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
},
)
console.log(dispatch)