mirror of
https://code.forgejo.org/actions/setup-forgejo.git
synced 2024-12-26 06:42:17 -05:00
add api function to the forgejo helper
This commit is contained in:
parent
3d6675b7ba
commit
22ff5f4704
1 changed files with 17 additions and 4 deletions
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue