diff --git a/forgejo-test-helper.sh b/forgejo-test-helper.sh index 35fefdf..e555c0f 100755 --- a/forgejo-test-helper.sh +++ b/forgejo-test-helper.sh @@ -9,15 +9,28 @@ DIR=$(mktemp -d) trap "rm -fr $DIR" EXIT +function api() { + method=$1 + shift + url=$1 + shift + path=$1 + shift + token=$1 + + if ! which jq curl > /dev/null ; then + apt-get -qq install -y jq curl + fi + + curl --fail -X $method -sS -H "Content-Type: application/json" -H "Authorization: token $token" "$@" $url/api/v1/$path +} + function check_status() { local url="$1" local repo="$2" local sha="$3" - if ! which jq > /dev/null ; then - apt-get install -y -qq jq - fi - local state=$(curl --fail -sS "$url/api/v1/repos/$repo/commits/$sha/status" | jq --raw-output .state) + local state=$(api GET $url repos/$repo/commits/$sha/status | jq --raw-output .state) echo $state test "$state" != "" -a "$state" != "pending" -a "$state" != "running" -a "$state" != "null" }