added in delete of pkg on transfer

This commit is contained in:
Trevor Batley 2023-06-05 10:41:39 +10:00
parent 1116647ec2
commit 75aa177430

View File

@ -282,25 +282,62 @@ 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
# Transfer back into the source organisation # Do we want to transfer the new package into the source organisation
if [ $TRANSFER ] ; then if [ $TRANSFER ] ; then
RESPONSE=$(curl "$SILENT" "$checkSSL" -o /dev/null -w "%{http_code}" -X 'POST' \ #Check that target package does not exist
"$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG/transfer" \ if [ $DEBUG ] ; then echo "Check if $SORCEORG/$TARGETPKG is there!" ; fi
-H 'accept: application/json' \ RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$SOURCEORG/$TARGETPKG")
-H "Authorization: token $GITEAACCESSTOKEN" \ EXISTS=
-H 'Content-Type: application/json' \ if [ "$RESPONSE" == "200" ]; then
-d '{ EXISTS=true
"new_owner": "'"$SOURCEORG"'" if [ $DEBUG ] ; then echo "Repository for $SOURCEORG/$TARGETPKG exists!" ; fi
}' if [ -z ${DELETEIT} ] ; then
) while true; do
if [[ $RESPONSE != "202" ]] ; then read -p "$SOURCEORG/$TARGETPKG exists! Do you wish to delete it and continue?(y/n) " yn
echo "Unable to transfer $TARGETORG/$TARGETPKG back to $SOURCEORG - Aborting!" case $yn in
[Yy]* )
DELETEIT=true
break ;;
[Nn]* )
DELETEIT=
break ;;
* ) echo "Please answer yes or no.";;
esac
done
fi
if [ $DELETEIT ] ; then
if [ $DEBUG ] ; then echo "Deleting $TARGETORG/$TARGETPKG" ; fi
RESPONSE=$(curl "$checkSSL" "$SILENT" -X 'DELETE' \
"$GITEAHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \
-H 'accept: application/json' \
-H "Authorization: token $GITEAACCESSTOKEN" )
EXISTS=
fi
else
if [ $DEBUG ] ; then echo "Repository for $SOURCEORG/$TARGETPKG does not exist on $GITEAHOST" ; fi
fi
# Transfer the package back to source organisation
if [[ -z $EXISTS ]] ; then
RESPONSE=$(curl "$SILENT" "$checkSSL" -o /dev/null -w "%{http_code}" -X 'POST' \
"$GITEAHOST/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 [[ $EXISTS || $RESPONSE != "202" ]] ; then
echo "Unable to transfer $TARGETORG/$TARGETPKG to $SOURCEORG/$TARGETPKG ($RESPONSE) - Aborting!"
echo "But everything else has been done and $TARGETORG/$TARGETPKG should be complete." echo "But everything else has been done and $TARGETORG/$TARGETPKG should be complete."
exit 1 exit 1
else
if [[ -z $NOOUTPUT ]] ; then echo "$SOURCEORG/$SOURCEPKG has been renamed as $SOURCEORG/$TARGETPKG" ; fi
fi fi
else
if [[ -z $NOOUTPUT ]] ; then echo "$SOURCEORG/$SOURCEPKG has been renamed as $TARGETORG/$TARGETPKG" ; fi
fi fi
if [[ -z $NOOUTPUT ]] ; then
echo "$SOURCEORG/$SOURCEPKG has been renamed as $TARGETORG/$TARGETPKG"
fi
exit 0 exit 0