From 5a8314c5f09100608cd7e75b34e9d1e65c274203 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Fri, 15 Jul 2022 18:52:38 +0200 Subject: [PATCH] Fix: Skip existing repos instead of throwing an error --- gitlab-to-gitea.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/gitlab-to-gitea.py b/gitlab-to-gitea.py index c09c021..05ca7cb 100644 --- a/gitlab-to-gitea.py +++ b/gitlab-to-gitea.py @@ -33,8 +33,12 @@ gitlabClient = getGitlabClient() # migrate repos reposToMigrate = [] -projects = gitlabClient.projects.list( - search_namespaces=True, search="bluerock", iterator=True) +print("Loading repositories from Gitlab ...") +#projects = gitlabClient.projects.list( +# search_namespaces=True, search="max", iterator=True) +user = gitlabClient.users.list(username='fenoglio')[0] +projects = user.projects.list() + for project in projects: #print(project) #print(project.namespace['path'], project.name, project.visibility, project.http_url_to_repo) @@ -76,5 +80,17 @@ for project in projects: reposToMigrate.append(migration) for repo in reposToMigrate: - print("Migrating", repo['clone_addr'], "to owner", repo["repo_owner"], "with name", repo['repo_name']) + try: + existingRepo = repositoryApi.repo_get(repo["repo_owner"], repo['repo_name']) + skip = not existingRepo.empty + except gitea.rest.ApiException as e: + if e.status == 404: + skip = False + else: + raise e + + + print("Migrating", repo['clone_addr'], "to owner", repo["repo_owner"], "with name", repo['repo_name'], "[SKIPPED]" if skip else "") + if skip: + continue repositoryApi.repo_migrate(body=repo)