add api function to the forgejo helper

This commit is contained in:
Earl Warren 2023-04-02 16:02:16 +02:00
parent 3d6675b7ba
commit 22ff5f4704
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -9,15 +9,28 @@ DIR=$(mktemp -d)
trap "rm -fr $DIR" EXIT 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() { function check_status() {
local url="$1" local url="$1"
local repo="$2" local repo="$2"
local sha="$3" local sha="$3"
if ! which jq > /dev/null ; then local state=$(api GET $url repos/$repo/commits/$sha/status | jq --raw-output .state)
apt-get install -y -qq jq
fi
local state=$(curl --fail -sS "$url/api/v1/repos/$repo/commits/$sha/status" | jq --raw-output .state)
echo $state echo $state
test "$state" != "" -a "$state" != "pending" -a "$state" != "running" -a "$state" != "null" test "$state" != "" -a "$state" != "pending" -a "$state" != "running" -a "$state" != "null"
} }