forked from transferwise/actions-pr-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr-checker.sh
executable file
·102 lines (79 loc) · 2.76 KB
/
pr-checker.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
#
# Inspired by:
# https://github.com/FabianKoestring/body-regex-validator-action/blob/master/entrypoint.sh
#
set -e
DIR=$(dirname "$0")
source "${DIR}/defaults.sh"
source "${DIR}/functions.sh"
source "${DIR}/comparison.sh"
main() {
GITHUB_EVENT_ACTION=$(jq --raw-output .action "$GITHUB_EVENT_PATH")
echo "GITHUB_EVENT_PATH: ${GITHUB_EVENT_PATH}"
echo "GITHUB_EVENT_ACTION: ${GITHUB_EVENT_ACTION}"
echo "GITHUB_EVENT_NAME: ${GITHUB_EVENT_NAME}"
# handle pull_request
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then # && "$GITHUB_EVENT_ACTION" == "opened"
export GITHUB_PULL_REQUEST_EVENT_TITLE=$(jq --raw-output .pull_request.title "$GITHUB_EVENT_PATH")
export GITHUB_PULL_REQUEST_EVENT_BODY=$(jq --raw-output .pull_request.body "$GITHUB_EVENT_PATH")
export GITHUB_PULL_REQUEST_EVENT_LABELS=$(jq --raw-output .pull_request.labels "$GITHUB_EVENT_PATH")
GITHUB_PULL_REQUEST_EVENT_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
echo "GITHUB_PULL_REQUEST_EVENT_NUMBER: ${GITHUB_PULL_REQUEST_EVENT_NUMBER}"
echo "PR_CONTAINS_PATTERN: ${PR_CONTAINS_PATTERN}"
echo "PR_NOT_CONTAINS_PATTERN: ${PR_NOT_CONTAINS_PATTERN}"
echo "GITHUB_PULL_REQUEST_EVENT_TITLE:"
echo "$GITHUB_PULL_REQUEST_EVENT_TITLE"
echo "GITHUB_PULL_REQUEST_EVENT_LABELS:"
echo "$GITHUB_PULL_REQUEST_EVENT_LABELS"
echo "GITHUB_PULL_REQUEST_EVENT_BODY:"
echo "$GITHUB_PULL_REQUEST_EVENT_BODY"
body_comparison && title_comparison && tags_comparison && no_comparison
if [[ $? -eq 0 ]]; then
send_check_success
else
send_check_failed
fi
else
echo "Unknown GitHub event!"
echo "Exited without error"
fi
exit 0
}
send_check_success() {
if [[ -n "$SUCCESS_EMOJI" ]]; then
sendReaction "$GITHUB_PULL_REQUEST_EVENT_NUMBER" "$SUCCESS_EMOJI"
echo "reaction sent"
fi
if [[ "$SUCCESS_APPROVES_PR" == true ]]; then
approvePr "$GITHUB_PULL_REQUEST_EVENT_NUMBER"
echo "pr approved"
fi
if [[ -n "$SUCCESS_COMMENT" ]]; then
sendComment "$GITHUB_PULL_REQUEST_EVENT_NUMBER" "$SUCCESS_COMMENT"
echo "sent success comment"
fi
}
send_check_failed() {
if [[ -n "$PR_COMMENT" ]]; then
if [[ "$SUCCESS_APPROVES_PR" == true ]]; then
requestChangesComment "$GITHUB_PULL_REQUEST_EVENT_NUMBER" "$PR_COMMENT"
echo "requested changes"
else
sendComment "$GITHUB_PULL_REQUEST_EVENT_NUMBER" "$PR_COMMENT"
echo "sent comment"
fi
fi
if [[ -n "$SUCCESS_EMOJI" ]]; then
removeReaction "$GITHUB_PULL_REQUEST_EVENT_NUMBER" "$SUCCESS_EMOJI"
echo "reaction removed"
fi
if [[ "$FAIL_CLOSES_PR" == true ]]; then
closeIssue "$GITHUB_PULL_REQUEST_EVENT_NUMBER"
echo "pr closed"
fi
if [[ "$FAIL_EXITS" == true ]]; then
exit 1
fi
}
main