-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_issues.sh
executable file
·75 lines (66 loc) · 2.25 KB
/
update_issues.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
#!/usr/bin/env bash
set -euo pipefail
server=$1
os=$2
key=$3
repo=$GITHUB_REPOSITORY
workflow=$GITHUB_RUN_ID
commit=$GITHUB_SHA
trigger=$GITHUB_EVENT_NAME
cd "./tests/$server"
fail_msg="Tests failed; see \"Run tests\" step for more information."
issue_title="\`$server\` failure on \`$os\`"
curl -sS --fail --header "authorization: Bearer $key" "$GITHUB_API_URL/repos/$repo/issues?state=open" > .issues
test -s .issues
# existing issue
if jq "map(select(.title == \"$issue_title\"))" .issues | jq '.[0]' -e | jq '.number' -e > .number
then
number=$(cat .number)
if test -f ".fail"
then
# ignore existing errors in PRs
if [ "$trigger" = "pull_request" ]; then echo "$fail_msg Ignoring existing issue #$number for this PR..."; exit 0; fi
echo "Existing issue found: #$number."
echo "$fail_msg"
exit 1
else
if [ "$trigger" = "pull_request" ]; then echo "Fix implemented; not closing issue #$number for a PR (will be closed on merge)..."; exit 0; fi
echo "Test passed; closing issue #$number..."
curl --request POST \
--url "$GITHUB_API_URL/repos/$repo/issues/$number/comments" \
--header "authorization: Bearer $key" \
--header 'content-type: application/json' \
--data "{ \
\"body\": \"Resolved @ $commit; see workflow [$workflow]($GITHUB_SERVER_URL/$repo/actions/runs/$workflow)\"\
}" \
--fail &> /dev/null
curl --request PATCH \
--url "$GITHUB_API_URL/repos/$repo/issues/$number" \
--header "authorization: Bearer $key" \
--header 'content-type: application/json' \
--data "{ \
\"state\": \"closed\"\
}" \
--fail &> /dev/null
exit 0
fi
fi
# no existing issue
if test -f ".fail"
then
# do not allow PRs to introduce failures
if [ "$trigger" = "pull_request" ]; then echo "$fail_msg Not creating new issue for a PR..."; exit 1; fi
curl --request POST \
--url "https://api.github.com/repos/$repo/issues" \
--header "authorization: Bearer $key" \
--header 'content-type: application/json' \
--data "{ \
\"title\": \"$issue_title\",\
\"body\": \"\`$server\` failure on \`$os\` @ $commit; see workflow [$workflow](https://github.com/$repo/actions/runs/$workflow) \n\n $(cat issue_body)\"\
}" \
--fail &> /dev/null
echo "$fail_msg"
exit 1
else
exit 0
fi