-
-
Save tarhan/3796c8c37ad214c6f5d7d52a00232ab1 to your computer and use it in GitHub Desktop.
Very simple migration script to move from gitlab to gogs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env bash | |
## Needs `jq` (https://stedolan.github.io/jq/) on PATH | |
## and a personal gogs token of yours. | |
## Obtain token from https://git.example.com/user/settings/applications | |
## Usage: | |
## ./migrate.sh $clone_url $project_name [$optional_group] | |
## Migrate a repository to gogs into the user namespace of the token-user | |
## ./migrate.sh [email protected]:group/repo.git repo | |
## Migrate a repository to gogs into the group namespace `group` (needs to exist) | |
## ./migrate.sh [email protected]:group/repo.git repo group | |
echo $1; | |
clone_url=$1 | |
name=$2 | |
org=$3 | |
GOGS_URL="https://git.example.com" | |
GOGS_TOKEN="yourpersonalgogstoken" | |
PWD=`pwd` | |
uuid=$(uuidgen) | |
git clone $1 $uuid; | |
cd $uuid; | |
if [ -z "$3" ] | |
then | |
clone_url=`curl -H "Authorization: token $GOGS_TOKEN" \ | |
-H "Accept: application/json" \ | |
-H "Content-Type:application/json" \ | |
--data '{"name": "'"$name"'", "description":"automatic migration", "private": true}' \ | |
https://git.example.com/api/v1/user/repos | jq -r '.ssh_url'` | |
else | |
clone_url=`curl -H "Authorization: token $GOGS_TOKEN" \ | |
-H "Accept: application/json" \ | |
-H "Content-Type:application/json" \ | |
--data '{"name": "'"$name"'", "description":"automatic migration", "private": true}' \ | |
https://git.example.com/api/v1/org/$org/repos | jq -r '.ssh_url'` | |
fi | |
echo $clone_url; | |
git remote add migration $clone_url; | |
git push --all migration; | |
git push --tags migration; | |
cd ..; | |
rm -Rf $uuid; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment