From 481e85a5330fe8f8164a5b1d7a4e1da3915cb17a Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 10 Feb 2023 23:46:25 -0800 Subject: [PATCH] trying to upgrade the giteapy version, bleh --- Pipfile | 1 - Pipfile.lock | 44 ++------------------------------------------ domain/Migrator.py | 43 +++++++++++++++++++++++++++++++++++++------ giteapy | 1 + main.py | 25 +++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 49 deletions(-) create mode 160000 giteapy diff --git a/Pipfile b/Pipfile index ac34ddc..c398b0d 100644 --- a/Pipfile +++ b/Pipfile @@ -4,7 +4,6 @@ verify_ssl = true name = "pypi" [packages] -giteapy = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 46ff1af..eb6410c 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "824c02127733d501ae21f3e5ccc7ee72fc4b2fe92bbca23c77ebd204d294b0fc" + "sha256": "fedbd2ab7afd84cf16f128af0619749267b62277b4cb6989ef16d4bef6e4eef2" }, "pipfile-spec": 6, "requires": { @@ -15,46 +15,6 @@ } ] }, - "default": { - "certifi": { - "hashes": [ - "sha256:35824b4c3a97115964b408844d64aa14db1cc518f6562e8d7261699d1350a9e3", - "sha256:4ad3232f5e926d6718ec31cfc1fcadfde020920e278684144551c91769c7bc18" - ], - "markers": "python_version >= '3.6'", - "version": "==2022.12.7" - }, - "giteapy": { - "hashes": [ - "sha256:2078c802a4626bf311e911c969c34b7d19fbe9175e2910e1965b24ff69221470" - ], - "index": "pypi", - "version": "==1.0.8" - }, - "python-dateutil": { - "hashes": [ - "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86", - "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9" - ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2.8.2" - }, - "six": { - "hashes": [ - "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926", - "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254" - ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.16.0" - }, - "urllib3": { - "hashes": [ - "sha256:076907bf8fd355cde77728471316625a4d2f7e713c125f51953bb5b3eecf4f72", - "sha256:75edcdc2f7d85b137124a6c3c9fc3933cdeaa12ecb9a6a959f22797a0feca7e1" - ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", - "version": "==1.26.14" - } - }, + "default": {}, "develop": {} } diff --git a/domain/Migrator.py b/domain/Migrator.py index 3941811..f86432a 100644 --- a/domain/Migrator.py +++ b/domain/Migrator.py @@ -1,6 +1,7 @@ -import giteapy +# import giteapy +import giteapy.giteapy import logging import sys @@ -103,13 +104,22 @@ class Migrator: def migrate_entire_org( self, - source_org: str, - destination_org: str, destination_repo_name: str, destination_topics: list + interactive: bool = True, + source_org: str = None, source_topics: list[str] = None, + destination_org: str = None, destination_repo_name: str = None, destination_topics: list = None ): + assert source_org is not None, "Source org must be specified" + assert destination_org is not None, "Destination org must be specified" + assert destination_repo_name is not None, "Destination repo name must be specified" + assert destination_topics is not None, "Destination topics must be specified" api_source, api_destination = self._get_org_apis() + api_source: giteapy.OrganizationApi + api_destination: giteapy.OrganizationApi - source_repos = api_source.org_list_repos(source_org) + api_source_repos = self._get_repo_api(hostname=self.__source_host, port=self.__source_port, token=self.__source_token) + + source_repos = api_source.org_list_repos(source_org, page=0, limit=1000000) self.__logger.info(f"Found {len(source_repos)} repos on source:") for repo in source_repos: repo: giteapy.Repository @@ -124,10 +134,27 @@ class Migrator: repo: giteapy.Repository + repo_topics = api_source_repos.repo_list_topics(owner=repo.owner.login, repo=repo.name) + repo_topics = repo_topics.topics + self.__logger.error(f"Repo topics: {repo_topics}") + + if self._check_source_repo_topics(repo=repo, topics=source_topics) is False: + repos_ignore.append(repo) + self.__logger.info( + f"Ignoring repo because it doesn't have all required tags." + f"\n> Repo: {repo.full_name}" + f"\n> Has: {repo_topics}" + f"\n> Needs: {source_topics}" + ) + continue + while True: - response = input(f"Migrate repo #{repo.id} \"{repo.full_name}\" ? (Y)es, (N)o, (G)o right now, (Q)uit ==> ") - response = response.lower() + if interactive: + response = input(f"Migrate repo #{repo.id} \"{repo.full_name}\" ? (Y)es, (N)o, (G)o right now, (Q)uit ==> ") + response = response.lower() + else: + response = "y" valid_input = True if response == "y": @@ -192,6 +219,10 @@ class Migrator: else: self.__logger.info("Confirmation not received; Won't do anything.") + def _check_source_repo_topics(self, repo: giteapy.Repository, topics: list[str]) -> bool: + + return False + def _migrate_repos( self, destination_org_name: str, diff --git a/giteapy b/giteapy new file mode 160000 index 0000000..e0a089b --- /dev/null +++ b/giteapy @@ -0,0 +1 @@ +Subproject commit e0a089bdfb7ef6130b43727c50e78f176379db20 diff --git a/main.py b/main.py index e56eeac..496927c 100644 --- a/main.py +++ b/main.py @@ -37,6 +37,14 @@ def main(): required=True, help="Name of the source organization" ) + parser.add_argument( + "--source-required-topic", "--source-topic", + dest="source_topics", + default=[], + action="append", + help="Specify zero or more topics required topics for source repositories." + " Any repository that doesn't have all required topics will be skipped" + ) parser.add_argument( "--destination-hostname", "--dest-hostname", "--destination-host", "--dest-host", @@ -78,6 +86,21 @@ def main(): help="Specify zero or more topics to add to each destination repository" ) + parser.add_argument( + "--interactive", + dest="interactive", + default=True, + action="store_true", + help="Ask to confirm each migration.", + ) + parser.add_argument( + "--no-interactive", "--non-interactive", + dest="interactive", + default=True, + action="store_false", + help="Do not ask to confirm each migration; Migrate all repos quickly.", + ) + parser.add_argument( "--no-verify-ssl", dest="verify_ssl", @@ -97,7 +120,9 @@ def main(): ) mig.set_verify_ssl(args.verify_ssl) mig.migrate_entire_org( + interactive=args.interactive, source_org=args.source_org, + source_topics=args.source_topics, destination_org=args.destination_org, destination_repo_name=args.destination_repo_name, destination_topics=args.destination_topics