add review option

This commit is contained in:
Trevor Batley 2023-05-12 08:39:20 +10:00
parent 11f2f53a3e
commit 4a855c986b

View File

@ -32,10 +32,12 @@ while read -r line || [[ -n "$line" ]]; do
done < "$inifilename" done < "$inifilename"
if [[ -z $1 ]] ; then if [[ -z $1 ]] ; then
echo "migrate-org.sh <source organisation> [<target organisation>]" echo "migrate-org.sh <source organisation> [<target organisation> <review>]"
echo "<target organisation> is optional and will default to the gitea user" echo "<target organisation> is optional and will default to the gitea user"
echo "<review> is optional and will echo the changes, but not execute"
exit 0 exit 0
fi fi
DEBUG= DEBUG=
curlsilent="-s" curlsilent="-s"
if [ ${smegit_DEBUG} == true ] ; then DEBUG=true ; fi if [ ${smegit_DEBUG} == true ] ; then DEBUG=true ; fi
@ -43,13 +45,15 @@ if [ $DEBUG ] ; then
echo "found ini file: $inifilename" echo "found ini file: $inifilename"
curlsilent="-v" curlsilent="-v"
fi fi
MIRROR="copy" MIRROR="copy"
TARGETORG= TARGETORG=
#if [ $2 ] ; then TARGETORG=$2 ; fi for $param in $2 $3 $4; do
for $param in $2 $3 ; do
if [ $param ] ; then if [ $param ] ; then
if [[ $param == "copy" || $param == "mirror" ]] ; then if [[ $param == "copy" || $param == "mirror" ]] ; then
MIRROR=$param MIRROR=$param
elif [[ $param == "review"]] ; then
REVIEW=true
else else
TARGETORG=$param TARGETORG=$param
fi fi
@ -58,7 +62,6 @@ for $param in $2 $3 ; do
fi fi
done done
REMOTEACCESSTOKEN=${remote_GITEAACCESSTOKEN} REMOTEACCESSTOKEN=${remote_GITEAACCESSTOKEN}
LOCALACCESSTOKEN=${local_GITEAACCESSTOKEN} LOCALACCESSTOKEN=${local_GITEAACCESSTOKEN}
REMOTEGITEAHOST=${remote_GITEAHOST} REMOTEGITEAHOST=${remote_GITEAHOST}
@ -74,6 +77,17 @@ if [[ "$RESPONSE" != "200" ]] ; then
exit 1 exit 1
fi fi
if [[ ! $REVIEW ]] ; then
while true; do
read -p "Are you sure?(y/n) " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
fi
# get a list of repositories in the source organisation # get a list of repositories in the source organisation
for page in {1..10} ; do for page in {1..10} ; do
if [ $DEBUG ] ; then echo "getting page $page of repos from $REMOTEGITHOST $1" ; fi if [ $DEBUG ] ; then echo "getting page $page of repos from $REMOTEGITHOST $1" ; fi
@ -90,7 +104,11 @@ for page in {1..10} ; do
else else
echo $RESPONSE | grep -oP '(?<="name":").+?(?=")' | while read repo; do echo $RESPONSE | grep -oP '(?<="name":").+?(?=")' | while read repo; do
if [ $DEBUG ] ; then echo "git-migrate-repo.sh ${repo} $1 $TARGETORG $MIRROR" ; fi if [ $DEBUG ] ; then echo "git-migrate-repo.sh ${repo} $1 $TARGETORG $MIRROR" ; fi
if [[ $REVIEW ]] ; then
echo "git-migrate-repo.sh ${repo} $1 $TARGETORG $MIRROR"
else
git-migrate-repo.sh ${repo} $1 $TARGETORG $MIRROR git-migrate-repo.sh ${repo} $1 $TARGETORG $MIRROR
fi
done done
fi fi
done done