forked from libero/reviewer-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotify-github.sh
executable file
·64 lines (52 loc) · 1.36 KB
/
notify-github.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
#!/bin/bash
# MOVE THIS FILE TO https://github.com/libero/scripts/ once tested
set -e
unique_id=$(uuidgen)
temp_file="github-commit-status-${unique_id}.log"
function usage () {
echo "Usage: target_url=\"https://example.org\" repository=\"owner/repo\" description='Action finished' context=<context> commit=<commit sha> ./notify-github.sh";
}
if [ -z "$commit" ]; then
echo "Missing commit variable";
usage
exit 1;
fi
if [ -z "$repository" ]; then
echo "Missing repository variable";
usage
exit 1;
fi
if [ -z "$description" ]; then
echo "Missing description variable";
usage
exit 1;
fi
if [ -z "$target_url" ]; then
echo "Missing target_url variable";
usage
exit 1;
fi
if [ -z "$context" ]; then
echo "Missing context variable";
usage
exit 1;
fi
status="success"
status_code=$(curl \
-s \
-o "${temp_file}" \
-w '%{http_code}' \
"https://api.github.com/repos/$repository/statuses/$commit" \
-H "Content-Type: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
-X POST \
-d "{\"state\": \"$status\", \"description\": \"$description\", \"context\": \"$context\", \"target_url\": \"$target_url\"}")
echo "status code: $status_code"
if [[ $status_code -eq 201 ]]; then
rm "${temp_file}"
exit 0
fi
echo "HTTP ${status_code}"
cat "${temp_file}"
rm "${temp_file}"
exit 22 # standard curl -f exit code