diff --git a/rename-e-smith-pkg.sh b/rename-e-smith-pkg.sh index fa7e312..cc98113 100755 --- a/rename-e-smith-pkg.sh +++ b/rename-e-smith-pkg.sh @@ -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 [ ]" + echo "rename-e-smith-pkg.sh [ ]" echo " = Module/package name (e.g. e-smith-dnscache)" echo " can appear in any order and are optional" - echo " - (smeserver, smecontribs or user - defaults to smeserver)" + echo " - (any valid organisation - defaults to smeserver)" echo " - will use parameters set for local repository, else it will use remote" echo " - will automagically delete an existing repo, otherwise it will prompt" echo " - run in debug mode" - echo " - completely suppress all output" + echo " - 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