add gitlab migration script

This commit is contained in:
Matthias Kretschmann 2018-12-04 02:38:55 +01:00
parent e89d838ef4
commit db6722b761
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 66 additions and 3 deletions

View File

@ -1,6 +1,5 @@
<img align="left" src="logo-gitberlin-header.png" height="100">
## git.berlin
<img src="src/branch/master/logo-gitberlin-header.png" height="100">
# git.berlin
> Gitea installation [git.berlin](https://git.berlin) | git:git.berlin
---

64
migrate-gitlab-gitea.sh Normal file
View File

@ -0,0 +1,64 @@
#!/bin/sh
# https://gist.github.com/gregdel/870d58c80b80172445dc93294531d88c
#
# brew install jq
#
set -e
_usage() {
echo "Usage: $0 [--user|org] USER_OR_ORG_NAME GITEA_REPO_NAME GITLAB_HTTPS_URL"
exit 0
}
MODE=$1
GITEA_USERNAME=$2
GITEA_REPO_NAME=$3
GITLAB_CLONE_URL=$4
case $MODE in
--user|--org);;
*) _usage ;;
esac
[ -z "$GITLAB_CLONE_URL" ] && _usage
[ -z "$GITEA_REPO_NAME" ] && _usage
[ -z "$GITEA_USERNAME" ] && _usage
echo "Migrating $GITLAB_CLONE_URL to $GITEA_USERNAME/$GITEA_REPO_NAME"
GITEA_URL=${GITEA_URL:-"http://GITEA_URL"}
GITEA_TOKEN=${GITEA_TOKEN:-"YOUR_GITEA_TOKEN"}
GITLAB_USERNAME=${GITLAB_USERNAME:-"m"}
GITLAB_TOKEN=${GITLAB_TOKEN:-"YOUR_GITLAB_TOKEN"}
_api_call() {
# shellcheck disable=SC2086
curl -s -L -H "Authorization: token $GITEA_TOKEN" \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
"$GITEA_URL/api/v1/"$*
}
GITEA_UID=
[ "$MODE" = "--user" ] && GITEA_UID=$(_api_call "users/$GITEA_USERNAME" | jq .id)
[ "$MODE" = "--org" ] && GITEA_UID=$(_api_call "orgs/$GITEA_USERNAME" | jq .id)
echo "$GITEA_USERNAME has the user id $GITEA_UID"
migration_data=$(jq -n -c \
--arg name "$GITEA_REPO_NAME" \
--arg uid "$GITEA_UID" \
--arg clone_url "$GITLAB_CLONE_URL" \
--arg auth_username "$GITLAB_USERNAME" \
--arg auth_password "$GITLAB_TOKEN" \
'{
repo_name: $name,
clone_addr: $clone_url,
auth_username: $auth_username,
auth_password: $auth_password,
uid: $uid | tonumber,
private: true,
}'
)
_api_call repos/migrate --data "$migration_data" | jq .