65 lines
1.5 KiB
Bash
65 lines
1.5 KiB
Bash
|
#!/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 .
|