-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaction.yaml
72 lines (59 loc) · 2.51 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/pulls/review-requests#request-reviewers-for-a-pull-request
# 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: "Request review from reviewer for pull request"
description: "Requests a review from a reviewer for a pull request"
inputs:
github-token:
description: "GitHub token of a user with permission to request reviewers for a pull request"
required: true
reviewer:
description: "Username of user to request review from for 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: "Request reviewer"
uses: "actions/[email protected]"
env:
REVIEWER: "${{ inputs.reviewer }}"
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 reviewers = [
process.env.REVIEWER,
];
try {
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
pull_number: process.env.PULL_REQUEST_NUMBER,
repo: context.repo.repo,
reviewers: reviewers,
});
} catch (error) {
core.setFailed(error.message);
}