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
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 " 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 " - <force> will automagically delete an existing repo, otherwise it will prompt"
echo " - <debug> run in debug mode"
echo " - <nooutput> completely suppress all output"
echo " - <silent> suppress success message"
exit 0
fi
@ -65,24 +65,27 @@ else
fi
GITEAHOST=${remote_GITEAHOST}
SOURCEACCESSTOKEN=${remote_GITEAACCESSTOKEN}
GITEAACCESSTOKEN=${remote_GITEAACCESSTOKEN}
SOURCEORG="smeserver"
TARGETORG=${remote_USER}
DELETEIT=
NOOUTPUT=
TRANSFER=
for param in $2 $3 $4 $5 $6; do
if [ $param ] ; then
case $param in
local )
GITEAHOST=${local_GITEAHOST}
SOURCEACCESSTOKEN=${local_GITEAACCESSTOKEN}
GITEAACCESSTOKEN=${local_GITEAACCESSTOKEN}
TARGETORG=${local_USER} ;;
force )
DELETEIT=true ;;
debug )
DEBUG=true ;;
nooutput )
silent )
NOOUTPUT=true ;;
transfer )
TRANSFER=true ;;
* )
SOURCEORGORG=$param ;;
esac
@ -139,7 +142,7 @@ if [ "$RESPONSE" == "200" ]; then
RESPONSE=$(curl "$checkSSL" "$SILENT" -X 'DELETE' \
"$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \
-H 'accept: application/json' \
-H "Authorization: token $SOURCEACCESSTOKEN" )
-H "Authorization: token $GITEAACCESSTOKEN" )
fi
else
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' \
"$GITEAHOST/api/v1/repos/migrate" \
-H 'accept: application/json' \
-H "Authorization: token $SOURCEACCESSTOKEN" \
-H "Authorization: token $GITEAACCESSTOKEN" \
-H 'Content-Type: application/json' \
-d '{
"auth_token": "'"$SOURCEACCESSTOKEN"'",
"auth_token": "'"$GITEAACCESSTOKEN"'",
"clone_addr": "'"$GITEAHOST/$SOURCEORG/$SOURCEPKG.git"'",
"description": "'"SMEServer Koozali developed git repo for $TARGETPKG $BASEORCONTRIB"'",
"repo_name": "'"$TARGETPKG"'",
@ -178,7 +181,7 @@ WIKILINK=$(curl "$SILENT" -X 'GET' \
"$GITEAHOST/api/v1/repos/$SOURCEORG/$SOURCEPKG" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: token $SOURCEACCESSTOKEN" | \
-H "Authorization: token $GITEAACCESSTOKEN" | \
jq -r ' .external_wiki.external_wiki_url')
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' \
"$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \
-H 'accept: application/json' \
-H "Authorization: token $SOURCEACCESSTOKEN" \
-H "Authorization: token $GITEAACCESSTOKEN" \
-H 'Content-Type: application/json' \
-d '{
"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 push origin &> /dev/null
#Convert repository to a Regular Repository (rather than fork)
#Can't do via API call ATM, so leave a message
# Transfer back into the source organisation
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
echo "$SOURCEORG/$SOURCEPKG has been renamed as $TARGETORG/$TARGETPKG"
fi