Also add ability to copy source topics
This commit is contained in:
		@@ -102,15 +102,17 @@ class Migrator:
 | 
			
		||||
		self.__verify_ssl = b
 | 
			
		||||
	
 | 
			
		||||
	def migrate_entire_org(
 | 
			
		||||
		self,
 | 
			
		||||
		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
 | 
			
		||||
			self,
 | 
			
		||||
			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,
 | 
			
		||||
			do_destination_copy_topics: bool = True
 | 
			
		||||
	):
 | 
			
		||||
		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"
 | 
			
		||||
		assert do_destination_copy_topics is not None, "Destination directive to copy source topics should be specified"
 | 
			
		||||
		
 | 
			
		||||
		# api_source, api_destination = self._get_org_apis()
 | 
			
		||||
		api_source: giteapy.OrganizationApi
 | 
			
		||||
@@ -198,6 +200,7 @@ class Migrator:
 | 
			
		||||
					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.")
 | 
			
		||||
@@ -288,6 +291,7 @@ class Migrator:
 | 
			
		||||
			destination_org_name: str,
 | 
			
		||||
			destination_repo_name: str,
 | 
			
		||||
			destination_topics: list,
 | 
			
		||||
			do_destination_copy_topics: bool,
 | 
			
		||||
			repos: list
 | 
			
		||||
	):
 | 
			
		||||
		
 | 
			
		||||
@@ -295,9 +299,13 @@ class Migrator:
 | 
			
		||||
		
 | 
			
		||||
		destination_org = api_destination.org_get(org=destination_org_name)
 | 
			
		||||
		destination_org: giteapy.Organization
 | 
			
		||||
		
 | 
			
		||||
		self.__logger.info(f"Destination organization: {destination_org.full_name}")
 | 
			
		||||
		
 | 
			
		||||
		api_source_repos = self._get_repo_api(
 | 
			
		||||
			hostname=self.__source_host, port=self.__source_port,
 | 
			
		||||
			token=self.__source_token
 | 
			
		||||
		)
 | 
			
		||||
		
 | 
			
		||||
		source_repos_successful = []
 | 
			
		||||
		for source_repo in repos:
 | 
			
		||||
			
 | 
			
		||||
@@ -305,6 +313,9 @@ class Migrator:
 | 
			
		||||
			
 | 
			
		||||
			this_destination_repo_name = destination_repo_name.replace("%N%", 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
 | 
			
		||||
			
 | 
			
		||||
			migrate_body = giteapy.MigrateRepoForm(
 | 
			
		||||
				mirror=False,
 | 
			
		||||
				clone_addr=source_repo.clone_url,
 | 
			
		||||
@@ -334,6 +345,17 @@ class Migrator:
 | 
			
		||||
			assert repo_new.name == this_destination_repo_name,\
 | 
			
		||||
				"New repository didn't end up with the correct name. Failure?"
 | 
			
		||||
			
 | 
			
		||||
			# Copy source topics?
 | 
			
		||||
			if do_destination_copy_topics:
 | 
			
		||||
				for topic in source_repo_topics:
 | 
			
		||||
					self.__logger.debug(f"Appending source topic to new repo: {topic}")
 | 
			
		||||
					destination_api.repo_add_topc(
 | 
			
		||||
						owner=destination_org.username,
 | 
			
		||||
						repo=repo_new.name,
 | 
			
		||||
						topic=topic,
 | 
			
		||||
					)
 | 
			
		||||
			
 | 
			
		||||
			# Add specified topics
 | 
			
		||||
			for topic in destination_topics:
 | 
			
		||||
				self.__logger.debug(f"Appending topic to new repo: {topic}")
 | 
			
		||||
				destination_api.repo_add_topc(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user