forked from abinoda/assignee-to-reviewer-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·43 lines (36 loc) · 1.11 KB
/
entrypoint.sh
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
#!/bin/bash
set -eu
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi
if [[ -z "$GITHUB_EVENT_NAME" ]]; then
echo "Set the GITHUB_EVENT_NAME env variable."
exit 1
fi
if [[ -z "$GITHUB_EVENT_PATH" ]]; then
echo "Set the GITHUB_EVENT_PATH env variable."
exit 1
fi
API_HEADER="Accept: application/vnd.github.v3+json; application/vnd.github.antiope-preview+json"
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
action=$(jq --raw-output .action "$GITHUB_EVENT_PATH")
number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
assignee=$(jq --raw-output .assignee.login "$GITHUB_EVENT_PATH")
update_review_request() {
curl -sSL \
-H "Content-Type: application/json" \
-H "${AUTH_HEADER}" \
-H "${API_HEADER}" \
-X $1 \
-d "{\"reviewers\":[\"${assignee}\"]}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${number}/requested_reviewers"
}
if [[ "$action" == "assigned" ]]; then
update_review_request 'POST'
elif [[ "$action" == "unassigned" ]]; then
update_review_request 'DELETE'
else
echo "Ignoring action ${action}"
exit 0
fi