Fix: Skip existing repos instead of throwing an error

This commit is contained in:
Dorian Zedler 2022-07-15 18:52:38 +02:00
parent b94e0db406
commit 5a8314c5f0
Signed by: dorian
GPG key ID: 989DE36109AFA354

View file

@ -33,8 +33,12 @@ gitlabClient = getGitlabClient()
# migrate repos # migrate repos
reposToMigrate = [] reposToMigrate = []
projects = gitlabClient.projects.list( print("Loading repositories from Gitlab ...")
search_namespaces=True, search="bluerock", iterator=True) #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: for project in projects:
#print(project) #print(project)
#print(project.namespace['path'], project.name, project.visibility, project.http_url_to_repo) #print(project.namespace['path'], project.name, project.visibility, project.http_url_to_repo)
@ -76,5 +80,17 @@ for project in projects:
reposToMigrate.append(migration) reposToMigrate.append(migration)
for repo in reposToMigrate: 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) repositoryApi.repo_migrate(body=repo)