|
|
@ -190,7 +190,9 @@ class Migrator:
|
|
|
|
for repo in repos_migrate:
|
|
|
|
for repo in repos_migrate:
|
|
|
|
repo: giteapy.Repository
|
|
|
|
repo: giteapy.Repository
|
|
|
|
destination_name = self._make_destination_repo_name(pattern=destination_repo_name, repo=repo)
|
|
|
|
destination_name = self._make_destination_repo_name(pattern=destination_repo_name, repo=repo)
|
|
|
|
self.__logger.info(f"#{repo.id} \"{repo.name}\" ==> \"{destination_name}\"")
|
|
|
|
self.__logger.info(
|
|
|
|
|
|
|
|
f"#{repo.id} \"{repo.name}\"\n> \"{destination_name}\""
|
|
|
|
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.__logger.info("No repos marked to migrate")
|
|
|
|
self.__logger.info("No repos marked to migrate")
|
|
|
|
|
|
|
|
|
|
|
@ -210,14 +212,27 @@ class Migrator:
|
|
|
|
if confirmation == "MIGRATE":
|
|
|
|
if confirmation == "MIGRATE":
|
|
|
|
|
|
|
|
|
|
|
|
self.__logger.info("Confirmation received; Processing ... ")
|
|
|
|
self.__logger.info("Confirmation received; Processing ... ")
|
|
|
|
source_repos_successful = self._migrate_repos(
|
|
|
|
source_repos_successful, source_repos_failed = self._migrate_repos(
|
|
|
|
destination_org_name=destination_org,
|
|
|
|
destination_org_name=destination_org,
|
|
|
|
destination_repo_name=destination_repo_name,
|
|
|
|
destination_repo_name=destination_repo_name,
|
|
|
|
destination_topics=destination_topics,
|
|
|
|
destination_topics=destination_topics,
|
|
|
|
do_destination_copy_topics=do_destination_copy_topics,
|
|
|
|
do_destination_copy_topics=do_destination_copy_topics,
|
|
|
|
repos=repos_migrate
|
|
|
|
repos=repos_migrate
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.__logger.info(f"{len(source_repos_successful)} of {len(repos_migrate)} repos successfully migrated.")
|
|
|
|
self.__logger.info(
|
|
|
|
|
|
|
|
f"{len(source_repos_successful)} of {len(repos_migrate)} repos successfully migrated."
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if len(source_repos_failed) > 0:
|
|
|
|
|
|
|
|
self.__logger.error(f"Failed to migrate {len(source_repos_failed)} repos:")
|
|
|
|
|
|
|
|
for repo, exception in source_repos_failed:
|
|
|
|
|
|
|
|
self.__logger.error(
|
|
|
|
|
|
|
|
f"> {repo.name}"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
self.__logger.error(f"Captured exception data:")
|
|
|
|
|
|
|
|
for repo, exception in source_repos_failed:
|
|
|
|
|
|
|
|
self.__logger.error(
|
|
|
|
|
|
|
|
f"Failed to migrate repo: {repo.name}\n> {exception}"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
self._delete_migrated_repos(source_org_name=source_org, repos=source_repos_successful)
|
|
|
|
self._delete_migrated_repos(source_org_name=source_org, repos=source_repos_successful)
|
|
|
|
|
|
|
|
|
|
|
@ -321,12 +336,15 @@ class Migrator:
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
source_repos_successful = []
|
|
|
|
source_repos_successful = []
|
|
|
|
|
|
|
|
source_repos_failed = []
|
|
|
|
for source_repo in repos:
|
|
|
|
for source_repo in repos:
|
|
|
|
|
|
|
|
|
|
|
|
source_repo: giteapy.Repository
|
|
|
|
source_repo: giteapy.Repository
|
|
|
|
|
|
|
|
|
|
|
|
this_destination_repo_name = destination_repo_name.replace("%N%", source_repo.name)
|
|
|
|
this_destination_repo_name = destination_repo_name.replace("%N%", source_repo.name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.__logger.info(f"Migrating: {source_repo.name} ==> {this_destination_repo_name}")
|
|
|
|
|
|
|
|
|
|
|
|
source_repo_topics = api_source_repos.repo_list_topics(owner=source_repo.owner.login, repo=source_repo.name)
|
|
|
|
source_repo_topics = api_source_repos.repo_list_topics(owner=source_repo.owner.login, repo=source_repo.name)
|
|
|
|
source_repo_topics = source_repo_topics.topics
|
|
|
|
source_repo_topics = source_repo_topics.topics
|
|
|
|
|
|
|
|
|
|
|
@ -347,12 +365,28 @@ class Migrator:
|
|
|
|
self.__logger.debug("Migrate body:")
|
|
|
|
self.__logger.debug("Migrate body:")
|
|
|
|
self.__logger.debug(migrate_body)
|
|
|
|
self.__logger.debug(migrate_body)
|
|
|
|
|
|
|
|
|
|
|
|
destination_api = self._get_repo_api(
|
|
|
|
try:
|
|
|
|
hostname=self.__destination_host,
|
|
|
|
destination_api = self._get_repo_api(
|
|
|
|
port=self.__destination_port,
|
|
|
|
hostname=self.__destination_host,
|
|
|
|
token=self.__destination_token,
|
|
|
|
port=self.__destination_port,
|
|
|
|
)
|
|
|
|
token=self.__destination_token,
|
|
|
|
repo_new = destination_api.repo_migrate(body=migrate_body)
|
|
|
|
)
|
|
|
|
|
|
|
|
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_repo, e)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
self.__logger.debug(f"Migration result: {repo_new}")
|
|
|
|
self.__logger.debug(f"Migration result: {repo_new}")
|
|
|
|
repo_new: giteapy.Repository
|
|
|
|
repo_new: giteapy.Repository
|
|
|
|
|
|
|
|
|
|
|
@ -380,10 +414,14 @@ class Migrator:
|
|
|
|
|
|
|
|
|
|
|
|
source_repos_successful.append(source_repo)
|
|
|
|
source_repos_successful.append(source_repo)
|
|
|
|
|
|
|
|
|
|
|
|
return source_repos_successful
|
|
|
|
return source_repos_successful, source_repos_failed
|
|
|
|
|
|
|
|
|
|
|
|
def _delete_migrated_repos(self, source_org_name: str, repos: list[giteapy.Repository]):
|
|
|
|
def _delete_migrated_repos(self, source_org_name: str, repos: list[giteapy.Repository]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(repos) == 0:
|
|
|
|
|
|
|
|
self.__logger.warning(f"Cannot delete any migrated repos because none were successful!")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
repo_api = self._get_repo_api(
|
|
|
|
repo_api = self._get_repo_api(
|
|
|
|
hostname=self.__source_host,
|
|
|
|
hostname=self.__source_host,
|
|
|
|
port=self.__source_port,
|
|
|
|
port=self.__source_port,
|
|
|
@ -392,7 +430,7 @@ class Migrator:
|
|
|
|
repo_api: giteapy.RepositoryApi
|
|
|
|
repo_api: giteapy.RepositoryApi
|
|
|
|
|
|
|
|
|
|
|
|
self.__logger.info("")
|
|
|
|
self.__logger.info("")
|
|
|
|
self.__logger.info("Can now delete the following successfully migrated repos:")
|
|
|
|
self.__logger.info(f"Can now delete {len(repos)} successfully migrated repos:")
|
|
|
|
for r in repos:
|
|
|
|
for r in repos:
|
|
|
|
self.__logger.info(f"> #{r.id} \"{r.full_name}\" ==> {r.clone_url}")
|
|
|
|
self.__logger.info(f"> #{r.id} \"{r.full_name}\" ==> {r.clone_url}")
|
|
|
|
|
|
|
|
|
|
|
|