diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2023-07-17 00:02:50 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2024-10-07 11:02:07 +0200 |
commit | f19307d8ab2a754f82241df258e3de3e451f1ba3 (patch) | |
tree | 16aa02acc1fdc9bdf7c098fff90c4327e8859b7e | |
parent | 23a181f84a8fcc291cf552d5db639aade2ab30bc (diff) | |
download | gosc-f19307d8ab2a754f82241df258e3de3e451f1ba3.tar.gz |
First version of git obranch
-rwxr-xr-x | git-obranch | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/git-obranch b/git-obranch index 484aee4..fba2251 100755 --- a/git-obranch +++ b/git-obranch @@ -1,16 +1,52 @@ #!/bin/sh +# Requires: coreutils, curl, jq, git set -ue -API_KEY="$(cat $(dirname $0)/gitea-api-token.txt)" - -# set -x +API_KEY="$(cat "$(dirname "$(readlink -f "$0")")"/gitea-api-token.txt)" [ "$#" -lt 2 ] && exit 1 -OUT=$(osc branch -c "$1" "$2"| tail -n 2 | head -n 1) +if [ "$1" = "openSUSE:Factory" ] ; then + OUT=$(osc develproject "$1" "$2") + DEVPRJ="$(dirname "$OUT")" + PKG="$(basename "$OUT")" +else + DEVPRJ="$1" + PKG="$2" +fi + +osc co -u -c "$DEVPRJ" "$PKG" || /bin/true +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 + +# 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 + +if [ -n "$FORKS" ] ; then + MY_FORK="$(echo "$FORKS"|grep -s "$LOGIN")" || /bin/true +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')" +fi + +# Add ignore +echo '.osc/' >> .git/info/exclude +echo '_scmsync.obsinfo' >> .git/info/exclude -echo $OUT -# # Fork -# curl -X 'POST' -H 'accept: application/json' -H 'Content-Type: application/json' \ -# -H "Authorization: token $API_KEY" \ -# "https://src.opensuse.org/api/v1/repos/pool/$1/forks" +# Set URLs for the forked repository +git remote add myproj "https://src.opensuse.org/$MY_FORK.git" +git remote set-url --push myproj "gitea@src.opensuse.org:$MY_FORK.git" |