diff options
-rwxr-xr-x | git-obranch | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/git-obranch b/git-obranch index fba2251..be93a7b 100755 --- a/git-obranch +++ b/git-obranch @@ -1,9 +1,15 @@ #!/bin/sh # Requires: coreutils, curl, jq, git -set -ue +set -uex API_KEY="$(cat "$(dirname "$(readlink -f "$0")")"/gitea-api-token.txt)" +gitea_cmd () { + curl -s -H 'accept: application/json' -H 'Content-Type: application/json' \ + -H "Authorization: token $API_KEY" \ + "https://src.opensuse.org/api/v1/$1" 2>/dev/null +} + [ "$#" -lt 2 ] && exit 1 if [ "$1" = "openSUSE:Factory" ] ; then @@ -20,27 +26,22 @@ cd "$PKG" # Fork # Whoami? -LOGIN=$(curl -s -H 'accept: application/json' -H 'Content-Type: application/json' \ - -H "Authorization: token $API_KEY" \ - "https://src.opensuse.org/api/v1/user" 2>/dev/null | jq -r '.login') || /bin/true +LOGIN=$(gitea_cmd "user" | jq -r '.login') || /bin/true # Check whether the fork already exists -FORKS="$(curl -s -H 'accept: application/json' -H 'Content-Type: application/json' \ - -H "Authorization: token $API_KEY" \ - "https://src.opensuse.org/api/v1/repos/pool/$PKG/forks" 2>/dev/null \ - | jq -r '.[].full_name' | grep -s -v '^rpm/')" || /bin/true +FORKS="$(gitea_cmd "repos/pool/$PKG/forks" \ + | jq -r '.[].full_name' | grep -s -v '^rpm/')" || /bin/true if [ -n "$FORKS" ] ; then MY_FORK="$(echo "$FORKS"|grep -s "$LOGIN")" || /bin/true +else + MY_FORK="" fi # If not, make a fork if [ -z "$MY_FORK" ] ; then - FRK_OUT="$(curl -s -X 'POST' -H 'accept: application/json' \ - -H 'Content-Type: application/json' \ - -H "Authorization: token $API_KEY" \ - "https://src.opensuse.org/api/v1/repos/pool/$PKG/forks" 2>/dev/null)" - MY_FORK="$(echo $FRK_OUT | jq -r '.full_name')" + FRK_OUT="$(gitea_cmd "repos/pool/$PKG/forks")" + MY_FORK="$(echo "$FRK_OUT" | jq -r '.[].full_name')" fi # Add ignore |