-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
start-ci.sh
executable file
·54 lines (43 loc) · 1.34 KB
/
start-ci.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
#!/bin/bash
set -xe
GITHUB_TOKEN=$1
OWNER=$2
REPOSITORY=$3
API_URL=https://api.github.com
REQUEST_CI_LABEL='request-ci'
REQUEST_CI_FAILED_LABEL='request-ci-failed'
shift 3
function issueUrl() {
echo "$API_URL/repos/${OWNER}/${REPOSITORY}/issues/${1}"
}
function labelsUrl() {
echo "$(issueUrl "${1}")/labels"
}
function commentsUrl() {
echo "$(issueUrl "${1}")/comments"
}
for pr in "$@"; do
curl -sL --request DELETE \
--url "$(labelsUrl "$pr")"/"$REQUEST_CI_LABEL" \
--header "authorization: Bearer ${GITHUB_TOKEN}" \
--header 'content-type: application/json'
ci_started=yes
rm -f output;
ncu-ci run "$pr" >output 2>&1 || ci_started=no
cat output
if [ "$ci_started" == "no" ]; then
# Do we need to reset?
curl -sL --request PUT \
--url "$(labelsUrl "$pr")" \
--header "authorization: Bearer ${GITHUB_TOKEN}" \
--header 'content-type: application/json' \
--data '{"labels": ["'"${REQUEST_CI_FAILED_LABEL}"'"]}'
jq -n --arg content "<details><summary>Couldn't start CI</summary><pre>$(cat output)</pre></details>" '{body: $content}' > output.json
curl -sL --request POST \
--url "$(commentsUrl "$pr")" \
--header "authorization: Bearer ${GITHUB_TOKEN}" \
--header 'content-type: application/json' \
--data @output.json
rm output.json;
fi
done;