abort on failed delete of existing repo

This commit is contained in:
Trevor Batley 2023-06-01 09:07:39 +10:00
parent c44114c672
commit 8ab6930155

View File

@ -257,13 +257,26 @@ fi
cd $GITFiles cd $GITFiles
#git init $QUIET $1 #git init $QUIET $1
# Now delete the remote repo and re-create it and clone it in to local # Work out if it is an SMEServer package or a 3rd party one
if [[ "$NAME" =~ ^(smeserver-|e-smith-).* ]]; then
PACKAGETYPE="SMEServer Koozali developed"
else
PACKAGETYPE="3rd Party (Maintained by Koozali)"
fi
# Now delete the repo, re-create it and clone it in to local
if [ $DEBUG ] ; then echo "Delete $ORGGITEA/$1" ; fi if [ $DEBUG ] ; then echo "Delete $ORGGITEA/$1" ; fi
curl "$checkSSL" "$curlsilent" -X 'DELETE' \ RESPONSE=$(curl "$checkSSL" "$curlsilent" -X 'DELETE' \
"$GITEAHOST/api/v1/repos/$ORGGITEA/$1" \ "$GITEAHOST/api/v1/repos/$ORGGITEA/$1" \
-H 'accept: application/json' \ -H 'accept: application/json' \
-H "Authorization: token $GITEAACCESSTOKEN" -H "Authorization: token $GITEAACCESSTOKEN")
if [[ $RESPONSE == "204" ]] ; then
if [ $DEBUG ] ; then echo "************Repository $ORGGITEA/$1 deleted or does not exist" ; fi
else
echo "************Can NOT delete Repository $ORGGITEA/$1 - results will be unknown - Aborting!"
echo "RESPONSE=$RESPONSE"
exit 1
fi
# and check if it is here. # and check if it is here.
if [ $DEBUG ] ; then echo "Check if $ORGGITEA/$1 is there!" ; fi if [ $DEBUG ] ; then echo "Check if $ORGGITEA/$1 is there!" ; fi
RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORGGITEA/$1") RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORGGITEA/$1")
@ -275,21 +288,11 @@ else
GOTREPO=1 GOTREPO=1
fi fi
# Work out if it is an SMEServer package or a 3rd party one
if [[ "$NAME" =~ ^(smeserver-|e-smith-).* ]]; then
PACKAGETYPE="SMEServer Koozali developed"
else
PACKAGETYPE="3rd Party (Maintained by Koozali)"
fi
# #
# Use the API interface to create the remote repo # Create the repo
# #
if [ $DEBUG ] ; then echo "************Creating repo for $1 $PACKAGETYPE" ; fi if [ $DEBUG ] ; then echo "************Creating repo for $1 $PACKAGETYPE" ; fi
RESPONSE=$(curl "$checkSSL" "$curlsilent" -X 'POST' "$GITEAHOST/api/v1/orgs/$ORGGITEA/repos" \
if [[ $GOTREPO -eq 1 ]] ; then
#Create it if it does not exist
JSONREPO=$(curl "$checkSSL" "$curlsilent" -X 'POST' "$GITEAHOST/api/v1/orgs/$ORGGITEA/repos" \
-H 'accept: application/json' \ -H 'accept: application/json' \
-H "Authorization: token $GITEAACCESSTOKEN" \ -H "Authorization: token $GITEAACCESSTOKEN" \
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
@ -306,31 +309,24 @@ if [[ $GOTREPO -eq 1 ]] ; then
"template": false, "template": false,
"trust_model": "Default Trust Model" "trust_model": "Default Trust Model"
}') }')
if [ $DEBUG ] ; then echo $RESPONSE ; fi
if [ $DEBUG ] ; then echo $JSONREPO ; fi
# and extract the http URL for it # and extract the http URL for it
HTTP_URL=`echo $JSONREPO | jq -r '.html_url'` HTTP_URL=`echo $RESPONSE | jq -r '.html_url'`
if [ $DEBUG ] ; then echo $HTTP_URL ; fi if [ $DEBUG ] ; then echo $HTTP_URL ; fi
if [[ -z "${HTTP_URL}" ]]; then
if [[ -z "${HTTP_URL}" ]]; then echo "ERROR*******Repo for $1 appears NOT to have been created "
echo "ERROR*******Repo for $1 appears NOT to have been created " echo "$RESPONSE"
echo "$JSONREQ" exit 1
exit 1 fi
fi
else
# Already there
HTTP_URL=$RemoteRepoURL
JSONREQ="$1 Already exists"
fi
# And check it now exists # And check it now exists
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORGGITEA/$1") RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORGGITEA/$1")
if [[ "$RESPONSE" == "200" ]]; then if [[ "$RESPONSE" == "200" ]]; then
if [ $DEBUG ] ; then echo "************Repository for $1 exists" ; fi if [ $DEBUG ] ; then echo "************Repository for $1 exists" ; fi
else else
echo "ERROR*******Repository for $1 has not been created ($JSONREQ)" echo "ERROR*******Repository for $1 has not been created ($RESPONSE)"
exit 1 exit 1
fi fi