Seems to be working now

This commit is contained in:
mike 2024-06-18 02:04:43 -07:00
parent 27a8f73390
commit ec81cab79d

View File

@ -392,98 +392,64 @@ class Migrator:
f"Migrating: {source_repo.name} ==> {this_destination_repo_name}" f"Migrating: {source_repo.name} ==> {this_destination_repo_name}"
) )
# source_repo_topics = api_source_repos.repo_list_topics( source_repo_topics = source_repo.get_topics()
# owner=source_repo.owner.login, repo=source_repo.name
# )
# source_repo_topics = source_repo_topics.topics
topics = source_repo.get_topics()
# migrate_body = giteapy.MigrateRepoForm( try:
# mirror=False,
# clone_addr=source_repo.clone_url,
# uid=destination_org.id,
# private=source_repo.private,
# repo_name=this_destination_repo_name,
# description=source_repo.description,
# labels=True, issues=True, pull_requests=True, releases=True, milestones=True, wiki=True
# )
# TODO: These three lines represent feature request to giteapy authors
#migrate_body.auth_token = self.__source_token
#migrate_body.swagger_types["auth_token"] = "str"
#migrate_body.attribute_map["auth_token"] = "auth_token"
destination_repo = gitea.Repository.migrate_repo( repo_new = gitea.Repository.migrate_repo(
gitea=self.__destination_api, gitea=self.__destination_api,
service: str, service="gitea", # type of remote service
clone_addr: str, clone_addr=source_repo.clone_url,
repo_name: str, repo_name=this_destination_repo_name,
description: str = "", description=source_repo.description,
private: bool = False, private=source_repo.private,
auth_token: str = None, auth_token=self.__source_token,
auth_username: str = None, auth_username=None,
auth_password: str = None, auth_password=None,
mirror: bool = False, mirror=False,
mirror_interval: str = None, mirror_interval=None,
lfs: bool = False, # lfs=False,
lfs_endpoint: str = "", # lfs_endpoint="",
wiki: bool = False, wiki=True,
labels: bool = False, labels=True,
issues: bool = False, issues=True,
pull_requests: bool = False, pull_requests=True,
releases: bool = False, releases=True,
milestones: bool = False, milestones=True,
repo_owner: str = None, repo_owner=destination_org_name,
) )
self.__logger.debug("Migrate body:") except Exception as e:
self.__logger.debug(migrate_body) self.__logger.error(
f"Failed to execute repo migration request:"
try: f"\n{e}"
destination_api = self._get_repo_api(
hostname=self.__destination_host,
port=self.__destination_port,
token=self.__destination_token,
) )
except giteapy.rest.ApiException as e:
self.__logger.error(f"Failed to generate destination API: {e}")
source_repos_failed.append(
(source_repo, e)
)
continue
try:
repo_new = destination_api.repo_migrate(body=migrate_body)
except giteapy.rest.ApiException as e:
self.__logger.error(f"Failed to execute repo migration request via API: {e}")
source_repos_failed.append( source_repos_failed.append(
(source_repo, e) (source_repo, e)
) )
continue continue
self.__logger.debug(f"Migration result: {repo_new}") self.__logger.debug(f"Migration result: {repo_new}")
repo_new: giteapy.Repository repo_new: gitea.Repository
assert repo_new.name == this_destination_repo_name,\ assert repo_new.name == this_destination_repo_name, \
"New repository didn't end up with the correct name. Failure?" "New repository didn't end up with the correct name. Failure?"
# Copy source topics? # Copy source topics?
if do_destination_copy_topics: if do_destination_copy_topics:
for topic in source_repo_topics: for topic in source_repo_topics:
self.__logger.debug(f"Appending source topic to new repo: {topic}") self.__logger.debug(f"Appending source topic to new repo: {topic}")
destination_api.repo_add_topc(
owner=destination_org.username, repo_new.add_topic(topic=topic)
repo=repo_new.name,
topic=topic,
)
# Add specified topics # Add specified topics
for topic in destination_topics: for topic in destination_topics:
self.__logger.debug(f"Appending topic to new repo: {topic}") self.__logger.debug(f"Appending topic to new repo: {topic}")
destination_api.repo_add_topc(
owner=destination_org.username, repo_new.add_topic(topic=topic)
repo=repo_new.name,
topic=topic,
)
source_repos_successful.append(source_repo) source_repos_successful.append(source_repo)
@ -495,20 +461,19 @@ class Migrator:
self.__logger.warning(f"Cannot delete any migrated repos because none were successful!") self.__logger.warning(f"Cannot delete any migrated repos because none were successful!")
return return
repo_api = self._get_repo_api(
hostname=self.__source_host,
port=self.__source_port,
token=self.__source_token
)
repo_api: giteapy.RepositoryApi
self.__logger.info("") self.__logger.info("")
self.__logger.info(f"Can now delete {len(repos)} successfully migrated repos:") self.__logger.info(f"Can now delete repos from source org: {source_org_name}")
self.__logger.info(f"Will delete {len(repos)} successfully migrated repos:")
for r in repos: for r in repos:
r: gitea.Repository
self.__logger.info(f"> #{r.id} \"{r.full_name}\" ==> {r.clone_url}") self.__logger.info(f"> #{r.id} \"{r.full_name}\" ==> {r.clone_url}")
response = input("Would you like to delete the successfully migrated repos? Type DELETE ==> ") # Ask the user to confirm deletion
response = input(
"Would you like to delete the successfully migrated repos? Type DELETE ==> "
)
if response != "DELETE": if response != "DELETE":
self.__logger.info("Okay, won't delete migrated repos.") self.__logger.info("Okay, won't delete migrated repos.")
return return
@ -517,7 +482,9 @@ class Migrator:
do_delete_all = False do_delete_all = False
for repo in repos: for repo in repos:
self.__logger.info(f"Next repo to delete: #{repo.id} \"{repo.full_name}\"") repo: gitea.Repository
self.__logger.info(f"Next repo to delete: \"{repo.full_name}\"")
do_delete = True if do_delete_all else False do_delete = True if do_delete_all else False
if do_delete is False: if do_delete is False:
@ -551,7 +518,4 @@ class Migrator:
self.__logger.info(f"Deleting repo: {repo.full_name}") self.__logger.info(f"Deleting repo: {repo.full_name}")
repo_api.repo_delete( repo.delete()
owner=source_org_name,
repo=repo.name
)