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