forked from ParanoidBeing/action-wip-blocker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·53 lines (42 loc) · 1.4 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
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
set -e
#Making sure we have the token
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi
#Making sure we have the block list
if [[ -z "$BLOCK_LIST" ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi
# skip if not a PR
echo "Checking if a PR command..."
(jq -r ".pull_request.url" "$GITHUB_EVENT_PATH") || exit 78
#Setting Required Headers
API_HEADER="Accept: application/vnd.github.v3+json; application/vnd.github.antiope-preview+json"
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
#Extracting pull request number
number=$(jq -r ".pull_request.number" "$GITHUB_EVENT_PATH")
#Calling the PR API to fetch latest info
#If the action had intially failed due to addition of a label or editing the title, it should pass if manually re-triggered
#later on, so we need to always work on the latest information.
RESPONSE=$(curl -s \
-H "Content-Type: application/json" \
-H "${AUTH_HEADER}" \
-H "${API_HEADER}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${number}")
#Extracting Title & Lables
title=$(jq ".title" <<< "$RESPONSE")
labels=$(jq ".labels" <<< "$RESPONSE")
#Block if suspect words are found.
#Todo - words to be provided as action input.
checkForBlockingWords(){
if echo "${1} ${2}" | grep -iE "$BLOCK_LIST"
then
return 1
else
return 0
fi
}
checkForBlockingWords "$title" "$labels"