diff options
Diffstat (limited to 'git-obranch')
-rwxr-xr-x | git-obranch | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/git-obranch b/git-obranch index be93a7b..5c30553 100755 --- a/git-obranch +++ b/git-obranch @@ -1,12 +1,13 @@ #!/bin/sh # Requires: coreutils, curl, jq, git -set -uex +set -ue API_KEY="$(cat "$(dirname "$(readlink -f "$0")")"/gitea-api-token.txt)" gitea_cmd () { + ADD_PARAMS=${2:-} curl -s -H 'accept: application/json' -H 'Content-Type: application/json' \ - -H "Authorization: token $API_KEY" \ + -H "Authorization: token $API_KEY" ${ADD_PARAMS[*]} \ "https://src.opensuse.org/api/v1/$1" 2>/dev/null } @@ -21,27 +22,28 @@ else PKG="$2" fi +# osc co should not finish with exit 1 osc co -u -c "$DEVPRJ" "$PKG" || /bin/true cd "$PKG" # Fork # Whoami? -LOGIN=$(gitea_cmd "user" | jq -r '.login') || /bin/true +LOGIN="$(gitea_cmd "user" | jq -r '.login')" # Check whether the fork already exists -FORKS="$(gitea_cmd "repos/pool/$PKG/forks" \ - | jq -r '.[].full_name' | grep -s -v '^rpm/')" || /bin/true +FRK_OUT="$(gitea_cmd "repos/pool/$PKG/forks")" +FORKS="$(echo $FRK_OUT | jq -r '.[].full_name | select(startswith("rpm/") | not)')" if [ -n "$FORKS" ] ; then - MY_FORK="$(echo "$FORKS"|grep -s "$LOGIN")" || /bin/true + MY_FORK="$(echo $FRK_OUT | jq -r ".[].full_name | select(startswith("$LOGIN/"))")" else MY_FORK="" fi # If not, make a fork if [ -z "$MY_FORK" ] ; then - FRK_OUT="$(gitea_cmd "repos/pool/$PKG/forks")" - MY_FORK="$(echo "$FRK_OUT" | jq -r '.[].full_name')" + FRK_OUT="$(gitea_cmd "repos/pool/$PKG/forks" "-X POST")" + MY_FORK="$(echo "$FRK_OUT" | jq -r '.full_name')" fi # Add ignore |