add additional params
This commit is contained in:
parent
6b45e5f846
commit
61f97c908e
@ -4,6 +4,13 @@
|
||||
#
|
||||
# migrate-repo.sh <reponame> <organisation> [<target organisation>]
|
||||
#
|
||||
if [[ -z $1 ]] ; then
|
||||
echo "git_migrate-repo.sh <reponame> <organisation> [<target organization> <copy|mirror> <local> <debug>]"
|
||||
echo "will migrate repo to local user unless <target organisation> specified"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# get config file and params
|
||||
inifilename=$(echo ~)"/.smegit/config"
|
||||
if [ ! -e $inifilename ] ; then
|
||||
# Not here, look at system default
|
||||
@ -31,62 +38,67 @@ while read -r line || [[ -n "$line" ]]; do
|
||||
fi
|
||||
done < $inifilename
|
||||
|
||||
if [[ -z $1 ]] ; then
|
||||
echo "git_migrate-repo.sh <reponame> <organisation> [<target organization>]"
|
||||
echo "will migrate repo to local user unless <target organisation> specified"
|
||||
exit 0
|
||||
fi
|
||||
DEBUG=
|
||||
if [ ${smegit_DEBUG} == true ] ; then DEBUG=true ; fi
|
||||
if [ $DEBUG ] ; then echo "found ini file: $inifilename" ; fi
|
||||
|
||||
curlsilent="-s"
|
||||
if [ $DEBUG ] ; then curlsilent="-v" ; fi
|
||||
SILENT="-s"
|
||||
if [ $DEBUG ] ; then SILENT="-v" ; fi
|
||||
|
||||
REMOTEACCESSTOKEN=${remote_GITEAACCESSTOKEN}
|
||||
LOCALACCESSTOKEN=${local_GITEAACCESSTOKEN}
|
||||
REMOTEGITEAHOST=${remote_GITEAHOST}
|
||||
CLONEADDRESS=$REMOTEGITEAHOST/$2/$1.git
|
||||
LOCALGITEAHOST=${local_GITEAHOST}
|
||||
SOURCEHOST=${remote_GITEAHOST}
|
||||
SOURCEACCESSTOKEN=${remote_GITEAACCESSTOKEN}
|
||||
TARGETGITEAHOST=${local_GITEAHOST}
|
||||
TARGETACCESSTOKEN=${local_GITEAACCESSTOKEN}
|
||||
TARGETORG=${local_USER}
|
||||
#if [ $3 ] ; then TARGETORG=$3 ; fi
|
||||
MIRROR="false"
|
||||
for param in $3 $4 ; do
|
||||
MIRROR=
|
||||
for param in $2 $3 $4 $5 $6; do
|
||||
if [ $param ] ; then
|
||||
if [[ $param == "copy" || $param == "mirror" ]] ; then
|
||||
if [ $param == "mirror" ] ; then MIRROR="true" ; fi
|
||||
else
|
||||
TARGETORG=$param
|
||||
fi
|
||||
case $param in
|
||||
local )
|
||||
SOURCEHOST=${local_GITEAHOST}
|
||||
SOURCEACCESSTOKEN=${local_GITEAACCESSTOKEN}
|
||||
CLONEADDRESS=$LOCALGITEAHOST/$2/$1.git
|
||||
;;
|
||||
copy )
|
||||
MIRROR=
|
||||
;;
|
||||
mirror )
|
||||
MIRROR=true ;;
|
||||
debug )
|
||||
DEBUG=true ;;
|
||||
* )
|
||||
TARGETORG=$param ;;
|
||||
esac
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
CLONEADDRESS=$SOURCEGITEAHOST/$2/$1.git
|
||||
if [ $DEBUG ] ; then
|
||||
echo "MIRROR=$MIRROR"
|
||||
echo "TARGETORG=$TARGETORG"
|
||||
fi
|
||||
|
||||
# check that the TARGETORG exists
|
||||
if [ $DEBUG ] ; then echo "checking if $TARGETORG exists on $LOCALGITEAHOST" ; fi
|
||||
RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG)
|
||||
if [ $DEBUG ] ; then echo "checking if $TARGETORG exists on $TARGETHOST" ; fi
|
||||
RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" $TARGETHOST/$TARGETORG)
|
||||
if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi
|
||||
if [[ "$RESPONSE" != "200" ]] ; then
|
||||
echo "$TARGETORG does not exist on $LOCALGITEAHOST"
|
||||
echo "$TARGETORG does not exist on $TARGETHOST"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# And check if this repo already exists on the target
|
||||
if [ $DEBUG ] ; then echo "checking if $TARGETORG/$1 already exists on $LOCALGITEAHOST" ; fi
|
||||
RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG/$1)
|
||||
if [ $DEBUG ] ; then echo "checking if $TARGETORG/$1 already exists on $TARGETHOST" ; fi
|
||||
RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" $TARGETHOST/$TARGETORG/$1)
|
||||
if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi
|
||||
if [ "$RESPONSE" == "200" ] ; then
|
||||
echo "Repository $TARGETORG/$1 already exists on $LOCALGITEAHOST - cannot migrate"
|
||||
echo "Repository $TARGETORG/$1 already exists on $TARGETHOST - cannot migrate"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DATA=$(cat << EOT
|
||||
"auth_token": "$REMOTEACCESSTOKEN",
|
||||
"auth_token": "$TARGETACCESSTOKEN",
|
||||
"clone_addr": "$CLONEADDRESS",
|
||||
"issues": true,
|
||||
"labels": true,
|
||||
@ -105,11 +117,11 @@ EOT
|
||||
)
|
||||
if [ $DEBUG ] ; then echo "JSON DATA=$DATA" ; fi
|
||||
|
||||
if [ $DEBUG ] ; then echo "Migrating $2/$1 as $TARGETORG/$1 on $LOCALGITEAHOST MIRROR=$MIRROR" ; fi
|
||||
RESPONSE=$(curl $curlsilent -k -X 'POST' \
|
||||
"$LOCALGITEAHOST/api/v1/repos/migrate" \
|
||||
if [ $DEBUG ] ; then echo "Migrating $2/$1 as $TARGETORG/$1 on $TARGETHOST MIRROR=$MIRROR" ; fi
|
||||
RESPONSE=$(curl $SILENT -k -X 'POST' \
|
||||
"$TARGETHOST/api/v1/repos/migrate" \
|
||||
-H 'accept: application/json' \
|
||||
-H "Authorization: token $LOCALACCESSTOKEN" \
|
||||
-H "Authorization: token $TARGETACCESSTOKEN" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "{ $DATA }"
|
||||
)
|
||||
@ -117,7 +129,7 @@ if [ $DEBUG ] ; then echo $? $RESPONSE ; fi
|
||||
|
||||
# And check if this repo is there
|
||||
if [ $DEBUG ] ; then echo "checking that $TARGETORG/$1 exists" ; fi
|
||||
RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG/$1)
|
||||
RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" $TARGETHOST/$TARGETORG/$1)
|
||||
if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi
|
||||
if [ "$RESPONSE" == "200" ] ; then
|
||||
msg="Repository $TARGETORG/$1 has been created"
|
||||
|
Loading…
Reference in New Issue
Block a user