add optional transfer back to source org

This commit is contained in:
Trevor Batley 2023-06-05 09:21:54 +10:00
parent 178d0f37ab
commit 2036ae59f4

View File

@ -12,14 +12,14 @@
if [[ -z $1 ]] ; then if [[ -z $1 ]] ; then
echo "Rename an e-smith package as smeserver and change relevant files" echo "Rename an e-smith package as smeserver and change relevant files"
echo "rename-e-smith-pkg.sh <modulename> [<organization> <local> <force> <debug>]" echo "rename-e-smith-pkg.sh <modulename> [<organization> <local> <force> <debug> <silent>]"
echo "<modulename> = Module/package name (e.g. e-smith-dnscache)" echo "<modulename> = Module/package name (e.g. e-smith-dnscache)"
echo " can appear in any order and are optional" echo " can appear in any order and are optional"
echo " - <organisation> (smeserver, smecontribs or user - defaults to smeserver)" echo " - <organisation> (any valid organisation - defaults to smeserver)"
echo " - <local> will use parameters set for local repository, else it will use remote" echo " - <local> will use parameters set for local repository, else it will use remote"
echo " - <force> will automagically delete an existing repo, otherwise it will prompt" echo " - <force> will automagically delete an existing repo, otherwise it will prompt"
echo " - <debug> run in debug mode" echo " - <debug> run in debug mode"
echo " - <nooutput> completely suppress all output" echo " - <silent> suppress success message"
exit 0 exit 0
fi fi
@ -65,24 +65,27 @@ else
fi fi
GITEAHOST=${remote_GITEAHOST} GITEAHOST=${remote_GITEAHOST}
SOURCEACCESSTOKEN=${remote_GITEAACCESSTOKEN} GITEAACCESSTOKEN=${remote_GITEAACCESSTOKEN}
SOURCEORG="smeserver" SOURCEORG="smeserver"
TARGETORG=${remote_USER} TARGETORG=${remote_USER}
DELETEIT= DELETEIT=
NOOUTPUT= NOOUTPUT=
TRANSFER=
for param in $2 $3 $4 $5 $6; do for param in $2 $3 $4 $5 $6; do
if [ $param ] ; then if [ $param ] ; then
case $param in case $param in
local ) local )
GITEAHOST=${local_GITEAHOST} GITEAHOST=${local_GITEAHOST}
SOURCEACCESSTOKEN=${local_GITEAACCESSTOKEN} GITEAACCESSTOKEN=${local_GITEAACCESSTOKEN}
TARGETORG=${local_USER} ;; TARGETORG=${local_USER} ;;
force ) force )
DELETEIT=true ;; DELETEIT=true ;;
debug ) debug )
DEBUG=true ;; DEBUG=true ;;
nooutput ) silent )
NOOUTPUT=true ;; NOOUTPUT=true ;;
transfer )
TRANSFER=true ;;
* ) * )
SOURCEORGORG=$param ;; SOURCEORGORG=$param ;;
esac esac
@ -139,7 +142,7 @@ if [ "$RESPONSE" == "200" ]; then
RESPONSE=$(curl "$checkSSL" "$SILENT" -X 'DELETE' \ RESPONSE=$(curl "$checkSSL" "$SILENT" -X 'DELETE' \
"$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \ "$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \
-H 'accept: application/json' \ -H 'accept: application/json' \
-H "Authorization: token $SOURCEACCESSTOKEN" ) -H "Authorization: token $GITEAACCESSTOKEN" )
fi fi
else else
if [ $DEBUG ] ; then echo "Repository for $TARGETORG/$TARGETPKG does not exist on $GITEAHOST" ; fi if [ $DEBUG ] ; then echo "Repository for $TARGETORG/$TARGETPKG does not exist on $GITEAHOST" ; fi
@ -161,10 +164,10 @@ if [ $DEBUG ] ; then echo "Migrating $SOURCEORG/$SOURCEPKG as $TARGETORG/$1 on $
RESPONSE=$(curl $SILENT -k -X 'POST' \ RESPONSE=$(curl $SILENT -k -X 'POST' \
"$GITEAHOST/api/v1/repos/migrate" \ "$GITEAHOST/api/v1/repos/migrate" \
-H 'accept: application/json' \ -H 'accept: application/json' \
-H "Authorization: token $SOURCEACCESSTOKEN" \ -H "Authorization: token $GITEAACCESSTOKEN" \
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
-d '{ -d '{
"auth_token": "'"$SOURCEACCESSTOKEN"'", "auth_token": "'"$GITEAACCESSTOKEN"'",
"clone_addr": "'"$GITEAHOST/$SOURCEORG/$SOURCEPKG.git"'", "clone_addr": "'"$GITEAHOST/$SOURCEORG/$SOURCEPKG.git"'",
"description": "'"SMEServer Koozali developed git repo for $TARGETPKG $BASEORCONTRIB"'", "description": "'"SMEServer Koozali developed git repo for $TARGETPKG $BASEORCONTRIB"'",
"repo_name": "'"$TARGETPKG"'", "repo_name": "'"$TARGETPKG"'",
@ -178,7 +181,7 @@ WIKILINK=$(curl "$SILENT" -X 'GET' \
"$GITEAHOST/api/v1/repos/$SOURCEORG/$SOURCEPKG" \ "$GITEAHOST/api/v1/repos/$SOURCEORG/$SOURCEPKG" \
-H 'accept: application/json' \ -H 'accept: application/json' \
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
-H "Authorization: token $SOURCEACCESSTOKEN" | \ -H "Authorization: token $GITEAACCESSTOKEN" | \
jq -r ' .external_wiki.external_wiki_url') jq -r ' .external_wiki.external_wiki_url')
if [ $DEBUG ] ; then echo "WIKILINK=$WIKILINK" ; fi if [ $DEBUG ] ; then echo "WIKILINK=$WIKILINK" ; fi
@ -187,7 +190,7 @@ if [ $DEBUG ] ; then echo "Updating Description, Bug and Wiki links" ; fi
RESPONSE=$(curl "$SILENT" "$checkSSL" -X 'PATCH' \ RESPONSE=$(curl "$SILENT" "$checkSSL" -X 'PATCH' \
"$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \ "$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \
-H 'accept: application/json' \ -H 'accept: application/json' \
-H "Authorization: token $SOURCEACCESSTOKEN" \ -H "Authorization: token $GITEAACCESSTOKEN" \
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
-d '{ -d '{
"has_issues": true, "has_issues": true,
@ -277,8 +280,16 @@ if [ -e archivefilename ] ; then git rm archivefilename $QUIET ; fi
git commit -m "rename-e-smith-pkg script (#12359)" $QUIET git commit -m "rename-e-smith-pkg script (#12359)" $QUIET
git push origin &> /dev/null git push origin &> /dev/null
#Convert repository to a Regular Repository (rather than fork) # Transfer back into the source organisation
#Can't do via API call ATM, so leave a message if [ $TRANSFER ] ; then
curl -X 'POST' \
"$GITEAURL/api/v1/repos/$TARGETORG/$TARGETPKG/transfer" \
-H 'accept: application/json' \
-H "Authorization: token $GITEAACCESSTOKEN" \
-H 'Content-Type: application/json' \
-d '{ "new_owner": "'"$SOURCEORG"'" }'
fi
if [[ -z $NOOUTPUT ]] ; then if [[ -z $NOOUTPUT ]] ; then
echo "$SOURCEORG/$SOURCEPKG has been renamed as $TARGETORG/$TARGETPKG" echo "$SOURCEORG/$SOURCEPKG has been renamed as $TARGETORG/$TARGETPKG"
fi fi