initial commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*~
|
||||||
57
README.md
Normal file
57
README.md
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
GitLab-to-Gitea Import Tools
|
||||||
|
============================
|
||||||
|
|
||||||
|
I knocked these together while migrating from a self-hosted GitLab CE
|
||||||
|
instance to a self-hosted Gitea instance. It should also prove useful for
|
||||||
|
migrating from gitlab.com. It is aimed mainly at batch-migrating
|
||||||
|
repositories for a single user, but admins could extend it to migrate
|
||||||
|
repositories for all users.
|
||||||
|
|
||||||
|
config.sh
|
||||||
|
---------
|
||||||
|
|
||||||
|
Set your GitLab and Gitea URLs, usernames, and access tokens here.
|
||||||
|
|
||||||
|
list-gitlab-projects.sh
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
This pulls a list of projects owned by the account associated with the
|
||||||
|
access token. Remove "&owned=true" for all projects on the instance...this
|
||||||
|
might be useful on a self-hosted GitLab, but probably should be left in
|
||||||
|
place for gitlab.com. :)
|
||||||
|
|
||||||
|
You might find it useful to filter the output to get just the repo names:
|
||||||
|
|
||||||
|
```./list-gitlab-projects.sh | sed "s/.*\///;s/\.git//" >repos.txt```
|
||||||
|
|
||||||
|
import.sh
|
||||||
|
---------
|
||||||
|
|
||||||
|
This fires off a request through the Gitea API to migrate a repository from
|
||||||
|
GitLab. It takes two arguments:
|
||||||
|
|
||||||
|
* repo name
|
||||||
|
* private flag (will import as a private repo unless this is set to
|
||||||
|
```false```)
|
||||||
|
|
||||||
|
You might want to call this from a script that batches up all your imports
|
||||||
|
together.
|
||||||
|
|
||||||
|
get-gitlab-container-repos.sh
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
This pulls a list of container image tags within your repositories. Once
|
||||||
|
you have this list, it's trivial to script up a ```docker image
|
||||||
|
pull```/```docker image push``` loop to transfer the images.
|
||||||
|
|
||||||
|
This script requires [jq](https://github.com/jqlang/jq) for some JSON
|
||||||
|
filtering. Your Linux distro probably has it. (Arch does, at least.)
|
||||||
|
|
||||||
|
delete-gitea-projects.sh
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
This is supposed to remove all projects in your Gitea account, but I found
|
||||||
|
that it might need to be run several times before it completely clears out
|
||||||
|
your account. It worked well enough for me to not have to wipe out the
|
||||||
|
entire Gitea instance and start over. Depending on your circumstances, you
|
||||||
|
might not need it.
|
||||||
15
config.sh
Normal file
15
config.sh
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# GitLab
|
||||||
|
GL_DOMAIN="https://gitlab.alfter.us"
|
||||||
|
GL_CR_DOMAIN="https://cr.gitlab.alfter.us"
|
||||||
|
GL_USER="salfter"
|
||||||
|
GL_TOKEN="glpat-PUT-YOUR-GITLAB-PERSONAL-ACCESS-TOKEN-HERE"
|
||||||
|
# a token with read-only access is sufficient
|
||||||
|
|
||||||
|
# Gitea
|
||||||
|
GT_DOMAIN="https://git.alfter.us"
|
||||||
|
# Gitea serves container images on the same domain, so GT_CR_DOMAIN isn't needed
|
||||||
|
GT_USER="salfter"
|
||||||
|
GT_TOKEN="PUT-YOUR-GITEA-ACCESS-TOKEN-HERE"
|
||||||
|
# a token with read/write access is required
|
||||||
17
delete-gitea-projects.sh
Executable file
17
delete-gitea-projects.sh
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# BUG: need to repeat until all repos are gone...it's not getting all of them
|
||||||
|
|
||||||
|
source config.sh
|
||||||
|
|
||||||
|
for ((i=1; ; i+=1)); do
|
||||||
|
contents=$(curl -sX GET "${GT_DOMAIN}/api/v1/user/repos?limit=30&page=${i}" -H "Accept: application/json" -H "Authorization: token ${GT_TOKEN}")
|
||||||
|
if [ "$(echo $contents | jq -e '. | length == 0')" == "true" ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
for repo in $(echo "$contents" | jq -r '.[].name')
|
||||||
|
do
|
||||||
|
echo $repo
|
||||||
|
curl -sX DELETE "${GT_DOMAIN}/api/v1/repos/${GT_USER}/${repo}" -H "Accept: application/json" -H "Authorization: token ${GT_TOKEN}"
|
||||||
|
done
|
||||||
|
done
|
||||||
13
get-gitlab-container-repos.sh
Normal file
13
get-gitlab-container-repos.sh
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source config.sh
|
||||||
|
|
||||||
|
SCOPE="registry:catalog:*"
|
||||||
|
|
||||||
|
token=$(curl -s --request GET \
|
||||||
|
--user "${GL_USER}:${GL_TOKEN}" \
|
||||||
|
--url "${GL_DOMAIN}/jwt/auth?service=container_registry&scope=${SCOPE}" | jq -r .token)
|
||||||
|
|
||||||
|
curl --header "Authorization: Bearer $token" \
|
||||||
|
--url "${GL_CR_DOMAIN}/v2/_catalog"
|
||||||
|
|
||||||
28
import.sh
Executable file
28
import.sh
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
source config.sh
|
||||||
|
|
||||||
|
if [ "$2" != "false" ]
|
||||||
|
then
|
||||||
|
private=true
|
||||||
|
else
|
||||||
|
private=false
|
||||||
|
fi
|
||||||
|
|
||||||
|
curl -sX 'POST' \
|
||||||
|
"${GT_DOMAIN}/api/v1/repos/migrate" \
|
||||||
|
-H 'accept: application/json' \
|
||||||
|
-H 'Authorization: token '${GT_TOKEN}'' \
|
||||||
|
-H 'Content-Type: application/json' \
|
||||||
|
-d '{
|
||||||
|
"auth_token": "'${GL_TOKEN}'",
|
||||||
|
"clone_addr": "'${GL_DOMAIN}'/'${GL_USER}'/'$1'",
|
||||||
|
"mirror": false,
|
||||||
|
"private": '$private',
|
||||||
|
"pull_requests": true,
|
||||||
|
"releases": true,
|
||||||
|
"repo_name": "'$1'",
|
||||||
|
"repo_owner": "'${GT_USER}'",
|
||||||
|
"service": "gitlab",
|
||||||
|
"wiki": true
|
||||||
|
}' | jq -r '.id'
|
||||||
9
list-gitlab-projects.sh
Executable file
9
list-gitlab-projects.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
source config.sh
|
||||||
|
for ((i=1; ; i+=1)); do
|
||||||
|
contents=$(curl -s "$GL_DOMAIN/api/v4/projects?private_token=$GL_TOKEN&per_page=100&owned=true&page=$i")
|
||||||
|
if jq -e '. | length == 0' >/dev/null; then
|
||||||
|
break
|
||||||
|
fi <<< "$contents"
|
||||||
|
echo "$contents" | jq -r '.[].ssh_url_to_repo'
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user