80 lines
2.5 KiB
Python
80 lines
2.5 KiB
Python
import gitea
|
|
import gitlab
|
|
|
|
import yaml
|
|
|
|
|
|
def getGiteaClient():
|
|
with open("/home/dorian/.config/tea/config.yml", "r") as stream:
|
|
teaConfig = yaml.safe_load(stream)
|
|
login = teaConfig['logins'][0]
|
|
|
|
conf = gitea.Configuration()
|
|
conf.host = f"{login['url']}/api/v1"
|
|
#conf.username = login['user']
|
|
conf.api_key = {"access_token": login['token']}
|
|
return gitea.ApiClient(conf)
|
|
|
|
|
|
def getGitlabClient():
|
|
with open("./gitlab-config.yml", "r") as stream:
|
|
gitlabConfig = yaml.safe_load(stream)
|
|
return gitlab.Gitlab(url=gitlabConfig['url'], private_token=gitlabConfig['private_token'])
|
|
|
|
|
|
giteaClient = getGiteaClient()
|
|
repositoryApi = gitea.api.RepositoryApi(giteaClient)
|
|
userApi = gitea.api.UserApi(giteaClient)
|
|
organizationApi = gitea.api.OrganizationApi(giteaClient)
|
|
currentUser = userApi.user_get_current()
|
|
|
|
gitlabClient = getGitlabClient()
|
|
|
|
# migrate repos
|
|
reposToMigrate = []
|
|
|
|
projects = gitlabClient.projects.list(
|
|
search_namespaces=True, search="bluerock", iterator=True)
|
|
for project in projects:
|
|
#print(project)
|
|
#print(project.namespace['path'], project.name, project.visibility, project.http_url_to_repo)
|
|
namespace = project.namespace
|
|
if namespace['kind'] == 'group':
|
|
try:
|
|
organizationApi.org_get(namespace['path'])
|
|
except gitea.rest.ApiException as e:
|
|
if e.status == 404:
|
|
# create organization!
|
|
group = gitlabClient.groups.get(namespace['path'])
|
|
#print(group)
|
|
organizationApi.org_create({
|
|
"full_name": namespace['name'],
|
|
"username": namespace['path'],
|
|
"description": group.description,
|
|
"visibility": "public"
|
|
})
|
|
pass
|
|
else:
|
|
raise e
|
|
|
|
migration = {
|
|
'auth_token': gitlabClient.private_token,
|
|
'auth_username': "dorian",
|
|
'clone_addr': project.http_url_to_repo,
|
|
'issues': True,
|
|
'labels': True,
|
|
'milestones': True,
|
|
'private': project.visibility == "private",
|
|
'pull_requests': True,
|
|
'releases': True,
|
|
'repo_name': project.path,
|
|
'service': "gitlab",
|
|
'wiki': True,
|
|
'repo_owner': project.namespace['path']
|
|
}
|
|
|
|
reposToMigrate.append(migration)
|
|
|
|
for repo in reposToMigrate:
|
|
print("Migrating", repo['clone_addr'], "to owner", repo["repo_owner"], "with name", repo['repo_name'])
|
|
repositoryApi.repo_migrate(body=repo)
|