• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3set -xe
4
5GITHUB_TOKEN=$1
6OWNER=$2
7REPOSITORY=$3
8API_URL=https://api.github.com
9REQUEST_CI_LABEL='request-ci'
10REQUEST_CI_FAILED_LABEL='request-ci-failed'
11shift 3
12
13issueUrl() {
14  echo "$API_URL/repos/${OWNER}/${REPOSITORY}/issues/${1}"
15}
16
17labelsUrl() {
18  echo "$(issueUrl "${1}")/labels"
19}
20
21commentsUrl() {
22  echo "$(issueUrl "${1}")/comments"
23}
24
25for pr in "$@"; do
26  curl -sL --request DELETE \
27       --url "$(labelsUrl "$pr")"/"$REQUEST_CI_LABEL" \
28       --header "authorization: Bearer ${GITHUB_TOKEN}" \
29       --header 'content-type: application/json'
30
31  ci_started=yes
32  rm -f output;
33  ncu-ci run "$pr" >output 2>&1 || ci_started=no
34  cat output
35
36  if [ "$ci_started" = "no" ]; then
37    # Do we need to reset?
38    curl -sL --request PUT \
39       --url "$(labelsUrl "$pr")" \
40       --header "authorization: Bearer ${GITHUB_TOKEN}" \
41       --header 'content-type: application/json' \
42       --data '{"labels": ["'"${REQUEST_CI_FAILED_LABEL}"'"]}'
43
44    jq -n --arg content "<details><summary>Couldn't start CI</summary><pre>$(cat output)</pre></details>" '{body: $content}' > output.json
45
46    curl -sL --request POST \
47       --url "$(commentsUrl "$pr")" \
48       --header "authorization: Bearer ${GITHUB_TOKEN}" \
49       --header 'content-type: application/json' \
50       --data @output.json
51
52    rm output.json;
53  fi
54done;
55