-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
56 lines (45 loc) · 1.69 KB
/
action.yml
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: 'Auto assign author'
description: 'Automatically assign the author of a pull request to the pull request.'
inputs:
token:
description: 'GitHub token to use. If passed, takes precedence over the `app-id` and `app-private-key` inputs.'
app-id:
description: 'The app ID of the app.'
private-key:
description: 'The private key of the app.'
runs:
using: composite
steps:
- uses: actions/checkout@v4
- uses: myparcelnl/actions/get-github-token@v4
id: token
with:
token: ${{ inputs.token }}
app-id: ${{ inputs.app-id }}
private-key: ${{ inputs.private-key }}
- name: 'Assign author'
uses: actions/github-script@v7
if: steps.check.outputs.assignable == 'true'
with:
github-token: ${{ steps.token.outputs.token }}
#language=javascript
script: |
if (context.payload.pull_request.assignees.length > 0) {
console.log('Pull request already has assignees.');
return;
}
const author = context.payload.pull_request.user.login;
const permission = await github.rest.repos.getCollaboratorPermissionLevel({
...context.repo,
username: author
});
if (permission.permission !== 'admin' && permission.permission !== 'write') {
console.log(`Author "${author}" does not have the required permissions to be assigned.`);
return;
}
github.rest.issues.addAssignees({
...context.repo,
issue_number: context.payload.pull_request.number,
assignees: [author]
});
console.log(`Assigned author "${author}" to pull request.`);