5 Commits

Author SHA1 Message Date
16ab8a2ffd Track+log some migration failures instead of actually failing 2023-12-28 05:11:21 -08:00
c6e2244694 Tweak logging 2023-12-28 05:10:54 -08:00
388a0235dd Log each repo during migration 2023-12-28 04:20:42 -08:00
06b90e515c README correction 2023-12-28 03:16:34 -08:00
cb06d54d4c Bump python and deps 2023-12-28 03:08:08 -08:00
5 changed files with 62 additions and 23 deletions

View File

@ -1 +1 @@
3.11.4
3.12.1

View File

@ -9,4 +9,5 @@ giteapy-soteria = {git = "https://github.com/Yousif-CS/giteapy.git"}
[dev-packages]
[requires]
python_version = "3.11"
python_version = "3.12"

18
Pipfile.lock generated
View File

@ -1,11 +1,11 @@
{
"_meta": {
"hash": {
"sha256": "22ccbf4d99003c4c606e34c887be35ec01c24dbb31211fcae66e04597514fb32"
"sha256": "5041607b8b692ebdc03484547b2d4336083196ff75b38c3140b608a7d59abaf8"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.11"
"python_version": "3.12"
},
"sources": [
{
@ -18,11 +18,11 @@
"default": {
"certifi": {
"hashes": [
"sha256:539cc1d13202e33ca466e88b2807e29f4c13049d6d87031a3c110744495cb082",
"sha256:92d6037539857d8206b8f6ae472e8b77db8058fec5937a1ef3f54304089edbb9"
"sha256:9b469f3a900bf28dc19b8cfbf8019bf47f7fdd1a65a1d4ffb98fc14166beb4d1",
"sha256:e036ab49d5b79556f99cfc2d9320b34cfbe5be05c5871b51de9329f0603b0474"
],
"markers": "python_version >= '3.6'",
"version": "==2023.7.22"
"version": "==2023.11.17"
},
"giteapy-soteria": {
"git": "https://github.com/Yousif-CS/giteapy.git",
@ -46,11 +46,11 @@
},
"urllib3": {
"hashes": [
"sha256:8d22f86aae8ef5e410d4f539fde9ce6b2113a001bb4d189e0aed70642d602b11",
"sha256:de7df1803967d2c2a98e4b11bb7d6bd9210474c46e8a0401514e3a42a75ebde4"
"sha256:55901e917a5896a349ff771be919f8bd99aff50b79fe58fec595eb37bbc56bb3",
"sha256:df7aa8afb0148fa78488e7899b2c59b5f4ffcfa82e6c54ccb9dd37c1d7b52d54"
],
"markers": "python_version >= '3.7'",
"version": "==2.0.4"
"markers": "python_version >= '3.8'",
"version": "==2.1.0"
}
},
"develop": {}

View File

@ -10,7 +10,7 @@ Current license: You are free to clone and use this program but all other rights
## Requirements
* python 3.10
* python 3.12
* pipenv
## Installation

View File

@ -190,7 +190,9 @@ class Migrator:
for repo in repos_migrate:
repo: giteapy.Repository
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:
self.__logger.info("No repos marked to migrate")
@ -210,14 +212,27 @@ class Migrator:
if confirmation == "MIGRATE":
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_repo_name=destination_repo_name,
destination_topics=destination_topics,
do_destination_copy_topics=do_destination_copy_topics,
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)
@ -321,12 +336,15 @@ class Migrator:
)
source_repos_successful = []
source_repos_failed = []
for source_repo in repos:
source_repo: giteapy.Repository
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 = source_repo_topics.topics
@ -347,12 +365,28 @@ class Migrator:
self.__logger.debug("Migrate body:")
self.__logger.debug(migrate_body)
try:
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_repo, e)
)
continue
self.__logger.debug(f"Migration result: {repo_new}")
repo_new: giteapy.Repository
@ -380,10 +414,14 @@ class Migrator:
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]):
if len(repos) == 0:
self.__logger.warning(f"Cannot delete any migrated repos because none were successful!")
return
repo_api = self._get_repo_api(
hostname=self.__source_host,
port=self.__source_port,
@ -392,7 +430,7 @@ class Migrator:
repo_api: giteapy.RepositoryApi
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:
self.__logger.info(f"> #{r.id} \"{r.full_name}\" ==> {r.clone_url}")