diff options
-rwxr-xr-x | git-obranch | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/git-obranch b/git-obranch index f49ce79..41dc19e 100755 --- a/git-obranch +++ b/git-obranch @@ -7,7 +7,7 @@ API_KEY="$(cat "$(dirname "$(readlink -f "$0")")"/gitea-api-token.txt)" gitea_cmd () { ADD_PARAMS=${2:-} # shellcheck disable=SC2048,SC2086 - curl -s -H 'accept: application/json' -H 'Content-Type: application/json' \ + curl -s -H 'Accept: application/json' -H 'Content-Type: application/json' \ -H "Authorization: token $API_KEY" ${ADD_PARAMS[*]} \ "https://src.opensuse.org/api/v1/$1" 2>/dev/null } @@ -36,6 +36,10 @@ fi # # Fork # Whoami? LOGIN="$(gitea_cmd "user" | jq -r '.login')" +# Do we have our own configuration for MYORG? +if ! MYORG="$(git config obs.org)" ; then + MYORG="${LOGIN}" +fi # Check whether the fork already exists FRK_OUT="$(gitea_cmd "repos/pool/$PKG/forks")" @@ -43,14 +47,20 @@ FORKS="$(echo "$FRK_OUT" | jq -r '.[].full_name | select(startswith("rpm/") | no if [ -n "$FORKS" ] ; then # shellcheck disable=SC2086 - MY_FORK="$(echo "$FRK_OUT" | jq -r ".[].full_name | select(startswith(\""$LOGIN/"\"))")" + MY_FORK="$(echo "$FRK_OUT" | jq -r ".[].full_name | select(startswith(\""$MYORG/"\"))")" else MY_FORK="" fi # If not, make a fork if [ -z "$MY_FORK" ] ; then - FRK_OUT="$(gitea_cmd "repos/pool/$PKG/forks" "-X POST")" + if [ "$MYORG" = "$LOGIN" ] ; then + FRK_OUT="$(gitea_cmd "repos/pool/$PKG/forks" "-X POST")" + else + # shellcheck disable=SC2086 + FRK_OUT="$(echo '{ "organization": "'$MYORG'" }' \ + | gitea_cmd "repos/pool/$PKG/forks" "-d @-")" + fi MY_FORK="$(echo "$FRK_OUT" | jq -r '.full_name')" fi |