-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaction.yaml
72 lines (59 loc) · 2.46 KB
/
action.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
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-run-steps-actions
# https://docs.github.com/en/rest/issues/assignees#add-assignees-to-an-issue
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_run
name: "Add assignee to pull request"
description: "Adds an assignee to a pull request"
inputs:
assignee:
description: "Username of user to add as an assignee to a pull request"
required: true
github-token:
description: "GitHub token of a user with permission to add assignees to a pull request"
required: true
runs:
using: "composite"
steps:
- name: "Determine pull request number"
uses: "actions/[email protected]"
with:
github-token: "${{ inputs.github-token }}"
script: |
if (
context.eventName == 'pull_request' ||
context.eventName == 'pull_request_target'
) {
core.exportVariable("PULL_REQUEST_NUMBER", context.payload.pull_request.number);
return;
}
if (context.eventName == 'workflow_run') {
core.exportVariable("PULL_REQUEST_NUMBER", context.payload.workflow_run.pull_requests[0].number);
return;
}
core.setFailed(`Unable to determine the pull request number for event "${context.eventName}"`);
- name: "Add assignee to pull request"
uses: "actions/[email protected]"
env:
ASSIGNEE: "${{ inputs.assignee }}"
with:
github-token: "${{ inputs.github-token }}"
script: |
if (!process.env.PULL_REQUEST_NUMBER) {
core.setFailed("The environment variable PULL_REQUEST_NUMBER is not defined.")
return;
}
const assignees = [
process.env.ASSIGNEE,
];
try {
await github.rest.issues.addAssignees({
assignees: assignees,
issue_number: process.env.PULL_REQUEST_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
});
} catch (error) {
core.setFailed(error.message);
}