From 22ff5f4704459b845c0dd620d6c3e111fb363a92 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Sun, 2 Apr 2023 16:02:16 +0200 Subject: [PATCH] add api function to the forgejo helper --- forgejo-test-helper.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) 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" }