From 4a855c986bbe4cb09a56e062ad22587bffbddecd Mon Sep 17 00:00:00 2001 From: Trevor Batley Date: Fri, 12 May 2023 08:39:20 +1000 Subject: [PATCH] add review option --- git-migrate-org.sh | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/git-migrate-org.sh b/git-migrate-org.sh index 313c7ea..c906fbc 100755 --- a/git-migrate-org.sh +++ b/git-migrate-org.sh @@ -32,10 +32,12 @@ while read -r line || [[ -n "$line" ]]; do done < "$inifilename" if [[ -z $1 ]] ; then - echo "migrate-org.sh []" + echo "migrate-org.sh [ ]" echo " is optional and will default to the gitea user" + echo " is optional and will echo the changes, but not execute" exit 0 fi + DEBUG= curlsilent="-s" if [ ${smegit_DEBUG} == true ] ; then DEBUG=true ; fi @@ -43,13 +45,15 @@ if [ $DEBUG ] ; then echo "found ini file: $inifilename" curlsilent="-v" fi + MIRROR="copy" TARGETORG= -#if [ $2 ] ; then TARGETORG=$2 ; fi -for $param in $2 $3 ; do +for $param in $2 $3 $4; do if [ $param ] ; then if [[ $param == "copy" || $param == "mirror" ]] ; then MIRROR=$param + elif [[ $param == "review"]] ; then + REVIEW=true else TARGETORG=$param fi @@ -58,7 +62,6 @@ for $param in $2 $3 ; do fi done - REMOTEACCESSTOKEN=${remote_GITEAACCESSTOKEN} LOCALACCESSTOKEN=${local_GITEAACCESSTOKEN} REMOTEGITEAHOST=${remote_GITEAHOST} @@ -74,6 +77,17 @@ if [[ "$RESPONSE" != "200" ]] ; then exit 1 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 for page in {1..10} ; do if [ $DEBUG ] ; then echo "getting page $page of repos from $REMOTEGITHOST $1" ; fi @@ -90,7 +104,11 @@ for page in {1..10} ; do else echo $RESPONSE | grep -oP '(?<="name":").+?(?=")' | while read repo; do if [ $DEBUG ] ; then echo "git-migrate-repo.sh ${repo} $1 $TARGETORG $MIRROR" ; fi - git-migrate-repo.sh ${repo} $1 $TARGETORG $MIRROR + if [[ $REVIEW ]] ; then + echo "git-migrate-repo.sh ${repo} $1 $TARGETORG $MIRROR" + else + git-migrate-repo.sh ${repo} $1 $TARGETORG $MIRROR + fi done fi done