forked from go-modules-by-example/index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sh
41 lines (32 loc) · 754 Bytes
/
common.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
#!/usr/bin/env bash
# this is a useful pre-amble to put in a script to help with testing via docker
# run directly
set -u
set -x
assert()
{
E_PARAM_ERR=98
E_ASSERT_FAILED=99
if [ -z "$2" ]
then
exit $E_PARAM_ERR
fi
lineno=$2
if [ ! $1 ]
then
echo "Assertion failed: \"$1\""
echo "File \"$0\", line $lineno"
exit $E_ASSERT_FAILED
fi
}
ensure_github_repo()
{
# TODO improve this
cat <<EOD | curl -s -H "Content-Type: application/json" -u $GITHUB_USERNAME:$GITHUB_PAT --request POST -d @- https://api.github.com/user/repos > /dev/null
{
"name": "$1"
}
EOD
curl -s -H "Content-Type: application/json" -u $GITHUB_USERNAME:$GITHUB_PAT https://api.github.com/repos/$GITHUB_USERNAME/$1 | grep -q '"id"'
}
# START