Add support for specifying the destination name pattern
This commit is contained in:
parent
5b1187cf65
commit
95b494e547
@ -8,6 +8,7 @@ import sys
|
|||||||
class Migrator:
|
class Migrator:
|
||||||
|
|
||||||
__DEFAULT_API_PATH = "/api/v1"
|
__DEFAULT_API_PATH = "/api/v1"
|
||||||
|
__REPO_ORIGINAL_NAME_TOKEN = "%N%"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -80,11 +81,21 @@ class Migrator:
|
|||||||
|
|
||||||
return base
|
return base
|
||||||
|
|
||||||
|
def _make_destination_repo_name(self, pattern: str, repo: giteapy.Repository):
|
||||||
|
|
||||||
|
repo_name = pattern.replace(self.__REPO_ORIGINAL_NAME_TOKEN, repo.name)
|
||||||
|
|
||||||
|
return repo_name
|
||||||
|
|
||||||
def set_verify_ssl(self, b: bool):
|
def set_verify_ssl(self, b: bool):
|
||||||
|
|
||||||
self.__verify_ssl = b
|
self.__verify_ssl = b
|
||||||
|
|
||||||
def migrate_entire_org(self, source_org, destination_org):
|
def migrate_entire_org(
|
||||||
|
self,
|
||||||
|
source_org: str,
|
||||||
|
destination_org: str, destination_repo_name: str, destination_topics: list
|
||||||
|
):
|
||||||
|
|
||||||
api_source, api_destination = self._get_org_apis()
|
api_source, api_destination = self._get_org_apis()
|
||||||
|
|
||||||
@ -137,7 +148,8 @@ class Migrator:
|
|||||||
self.__logger.info("Repos to migrate:")
|
self.__logger.info("Repos to migrate:")
|
||||||
for repo in repos_migrate:
|
for repo in repos_migrate:
|
||||||
repo: giteapy.Repository
|
repo: giteapy.Repository
|
||||||
self.__logger.info(f"#{repo.id} \"{repo.name}\"")
|
destination_name = self._make_destination_repo_name(pattern=destination_repo_name, repo=repo)
|
||||||
|
self.__logger.info(f"#{repo.id} \"{repo.name}\" ==> \"{destination_name}\"")
|
||||||
else:
|
else:
|
||||||
self.__logger.info("No repos marked to migrate")
|
self.__logger.info("No repos marked to migrate")
|
||||||
|
|
||||||
@ -154,11 +166,22 @@ class Migrator:
|
|||||||
confirmation = input("Do you confirm the above selections? Enter CONFIRM ==> ")
|
confirmation = input("Do you confirm the above selections? Enter CONFIRM ==> ")
|
||||||
if confirmation == "CONFIRM":
|
if confirmation == "CONFIRM":
|
||||||
self.__logger.info("Confirmation received; Processing ... ")
|
self.__logger.info("Confirmation received; Processing ... ")
|
||||||
self._migrate_repos(destination_org_name=destination_org, repos=repos_migrate)
|
self._migrate_repos(
|
||||||
|
destination_org_name=destination_org,
|
||||||
|
destination_repo_name=destination_repo_name,
|
||||||
|
destination_topics=destination_topics,
|
||||||
|
repos=repos_migrate
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
self.__logger.info("Confirmation not received; Won't do anything.")
|
self.__logger.info("Confirmation not received; Won't do anything.")
|
||||||
|
|
||||||
def _migrate_repos(self, destination_org_name: str, repos: list):
|
def _migrate_repos(
|
||||||
|
self,
|
||||||
|
destination_org_name: str,
|
||||||
|
destination_repo_name: str,
|
||||||
|
destination_topics: list,
|
||||||
|
repos: list
|
||||||
|
):
|
||||||
|
|
||||||
api_source, api_destination = self._get_org_apis()
|
api_source, api_destination = self._get_org_apis()
|
||||||
|
|
||||||
@ -171,12 +194,14 @@ class Migrator:
|
|||||||
|
|
||||||
repo: giteapy.Repository
|
repo: giteapy.Repository
|
||||||
|
|
||||||
|
this_destination_repo_name = destination_repo_name.replace("%N%", repo.name)
|
||||||
|
|
||||||
migrate_body = giteapy.MigrateRepoForm(
|
migrate_body = giteapy.MigrateRepoForm(
|
||||||
mirror=False,
|
mirror=False,
|
||||||
clone_addr=repo.clone_url,
|
clone_addr=repo.clone_url,
|
||||||
uid=destination_org.id,
|
uid=destination_org.id,
|
||||||
private=repo.private,
|
private=repo.private,
|
||||||
repo_name=repo.name,
|
repo_name=this_destination_repo_name,
|
||||||
description=repo.description,
|
description=repo.description,
|
||||||
labels=True, issues=True, pull_requests=True, releases=True, milestones=True, wiki=True
|
labels=True, issues=True, pull_requests=True, releases=True, milestones=True, wiki=True
|
||||||
)
|
)
|
||||||
@ -194,3 +219,6 @@ class Migrator:
|
|||||||
)
|
)
|
||||||
migration_result = destination_api.repo_migrate(body=migrate_body)
|
migration_result = destination_api.repo_migrate(body=migrate_body)
|
||||||
self.__logger.info(f"Migration result: {migration_result}")
|
self.__logger.info(f"Migration result: {migration_result}")
|
||||||
|
|
||||||
|
for t in destination_topics:
|
||||||
|
self.__logger.info(f"Want to append topic: {t}")
|
||||||
|
16
main.py
16
main.py
@ -64,6 +64,20 @@ def main():
|
|||||||
help="Name of the destination organization"
|
help="Name of the destination organization"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--destination-repo-name", "--destination-name", "--dest-repo-name", "--dest-name",
|
||||||
|
dest="destination_repo_name",
|
||||||
|
default="%N%",
|
||||||
|
help="Specify the destination repository name(s). Use wildcard %N% anywhere to denote the original name"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--destination-add-topic", "--destination-topic", "-dest-add-topic", "--dest-topic",
|
||||||
|
dest="destination_topics",
|
||||||
|
default=[],
|
||||||
|
action="append",
|
||||||
|
help="Specify zero or more topics to add to each destination repository"
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--no-verify-ssl",
|
"--no-verify-ssl",
|
||||||
dest="verify_ssl",
|
dest="verify_ssl",
|
||||||
@ -85,6 +99,8 @@ def main():
|
|||||||
mig.migrate_entire_org(
|
mig.migrate_entire_org(
|
||||||
source_org=args.source_org,
|
source_org=args.source_org,
|
||||||
destination_org=args.destination_org,
|
destination_org=args.destination_org,
|
||||||
|
destination_repo_name=args.destination_repo_name,
|
||||||
|
destination_topics=args.destination_topics
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user