refactor where Repository deleted

This commit is contained in:
Trevor Batley 2023-06-02 17:02:59 +10:00
parent 51551534f1
commit 3c94831315

View File

@ -233,6 +233,7 @@ fi
# See if it exists on the Gitea host # See if it exists on the Gitea host
REPO_NAME=$1 REPO_NAME=$1
if [ $DEBUG ] ; then echo "check that $GITEAHOST/$ORGGITEA/$REPO_NAME exists" ; fi if [ $DEBUG ] ; then echo "check that $GITEAHOST/$ORGGITEA/$REPO_NAME exists" ; fi
READMECONTENTS=
RESPONSE=$(curl $checkSSL $curlsilent -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORGGITEA/$REPO_NAME") RESPONSE=$(curl $checkSSL $curlsilent -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORGGITEA/$REPO_NAME")
if [ "$RESPONSE" == "200" ]; then if [ "$RESPONSE" == "200" ]; then
if [ $DEBUG ] ; then echo "************Repository for $1 already exists!" ; fi if [ $DEBUG ] ; then echo "************Repository for $1 already exists!" ; fi
@ -240,33 +241,33 @@ if [ "$RESPONSE" == "200" ]; then
# And Clone it # And Clone it
if [ $DEBUG ] ; then echo "git clone $GITEAHOST/$ORGGITEA/$1.git" ; fi if [ $DEBUG ] ; then echo "git clone $GITEAHOST/$ORGGITEA/$1.git" ; fi
cd $GITFiles cd $GITFiles
git clone "$GITEAHOST/$ORGGITEA/$1.git" git clone "$GITEAHOST/$ORGGITEA/$1.git"
#GIT_SSL_NO_VERIFY=true git clone "$GITEAHOST/$ORGGITEA/$1.git" if [[ -f $GITFILES/$1/README.md]] ; then
NOREPO=0
else
if [ $DEBUG ] ; then echo "************Repository for $1 does not exist." ; fi
NOREPO=1
fi
# then pull in the README
READMECONTENTS="";
cd $GITFiles
if [ -d "$1" ] ; then
cd $GITFiles/$1
# Retain the contents of the README.md (incase its been editted, and saving multiple GPT accesses)
if [ -f README.md ] ; then
# Move it and remember its new (temp) name # Move it and remember its new (temp) name
READMECONTENTS=`mktemp` READMECONTENTS=`mktemp`
mv -f README.md "$READMECONTENTS" mv -f README.md "$READMECONTENTS"
fi fi
if [ $DEBUG ] ; then echo "************Saved README: $READMECONTENTS" ; fi # Now delete the repo, re-create it and clone it in to local
if [ $DEBUG ] ; then echo "Delete $ORGGITEA/$1" ; fi
RESPONSE=$(curl "$checkSSL" "$curlsilent" -o /dev/null -w "{%http_code}" -X 'DELETE' \
"$GITEAHOST/api/v1/repos/$ORGGITEA/$1" \
-H 'accept: application/json' \
-H "Authorization: token $GITEAACCESSTOKEN")
if [[ $RESONSE == "204" || $RESPONSE == "404" ]] ; 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
# Delete all files, links and directories # Delete all files, links and directories
if [ $DEBUG ] ; then echo "************Deleting local GIT files" ; fi if [ $DEBUG ] ; then echo "************Deleting local GIT files" ; fi
cd $GITFiles cd $GITFiles
rm -Rf $GITFiles/$1 rm -Rf $GITFiles/$1
else
if [ $DEBUG ] ; then echo "************Repository for $1 does not exist." ; fi
fi fi
cd $GITFiles cd $GITFiles
#git init $QUIET $1 #git init $QUIET $1
@ -277,32 +278,8 @@ else
PACKAGETYPE="3rd Party (Maintained by Koozali)" PACKAGETYPE="3rd Party (Maintained by Koozali)"
fi fi
# Now delete the repo, re-create it and clone it in to local
if [ $DEBUG ] ; then echo "Delete $ORGGITEA/$1" ; fi
RESPONSE=$(curl "$checkSSL" "$curlsilent" -X 'DELETE' \
"$GITEAHOST/api/v1/repos/$ORGGITEA/$1" \
-H 'accept: application/json' \
-H "Authorization: token $GITEAACCESSTOKEN")
if [[ $RESPONSE == "204" || $RESPONSE == "404" ]] ; 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.
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")
if [ "$RESPONSE" == "200" ]; then
if [ $DEBUG ] ; then echo "************Repository for $1 exists!" ; fi
GOTREPO=0
else
if [ $DEBUG ] ; then echo "************Repository for $1 does not exist" ; fi
GOTREPO=1
fi
# #
# Create the repo # Re-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" \ RESPONSE=$(curl "$checkSSL" "$curlsilent" -X 'POST' "$GITEAHOST/api/v1/orgs/$ORGGITEA/repos" \