Now able to filter source repos by required tags
This commit is contained in:
		@@ -112,7 +112,7 @@ class Migrator:
 | 
				
			|||||||
		assert destination_repo_name is not None, "Destination repo name 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 destination_topics is not None, "Destination topics must be specified"
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		api_source, api_destination = self._get_org_apis()
 | 
							# api_source, api_destination = self._get_org_apis()
 | 
				
			||||||
		api_source: giteapy.OrganizationApi
 | 
							api_source: giteapy.OrganizationApi
 | 
				
			||||||
		api_destination: giteapy.OrganizationApi
 | 
							api_destination: giteapy.OrganizationApi
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
@@ -127,6 +127,7 @@ class Migrator:
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		# Filter
 | 
							# Filter
 | 
				
			||||||
		source_repos = self._filter_repos_for_required_topics(repos=source_repos, topics=source_topics)
 | 
							source_repos = self._filter_repos_for_required_topics(repos=source_repos, topics=source_topics)
 | 
				
			||||||
 | 
							print()
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		repos_migrate = []
 | 
							repos_migrate = []
 | 
				
			||||||
		repos_ignore = []
 | 
							repos_ignore = []
 | 
				
			||||||
@@ -226,7 +227,13 @@ class Migrator:
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		return source_repos
 | 
							return source_repos
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	def _filter_repos_for_required_topics(self, repos: list[giteapy.Repository], topics: list[str]) -> list[giteapy.Repository]:
 | 
						def _filter_repos_for_required_topics(
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								self,
 | 
				
			||||||
 | 
								repos: list[giteapy.Repository],
 | 
				
			||||||
 | 
								topics: list[str]
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
						) -> list[giteapy.Repository]:
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		self.__logger.info(f"Filtering source repos for required topics: {topics}")
 | 
							self.__logger.info(f"Filtering source repos for required topics: {topics}")
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
@@ -244,21 +251,21 @@ class Migrator:
 | 
				
			|||||||
			repo_topics[repo.id] = api_source_repos.repo_list_topics(owner=repo.owner.login, repo=repo.name)
 | 
								repo_topics[repo.id] = api_source_repos.repo_list_topics(owner=repo.owner.login, repo=repo.name)
 | 
				
			||||||
			repo_topics[repo.id] = repo_topics[repo.id].topics
 | 
								repo_topics[repo.id] = repo_topics[repo.id].topics
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			self.__logger.error(f"Repo topics: {repo_topics[repo.id]}")
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			if self._check_required_topics(topics_present=repo_topics[repo.id], topics_required=topics):
 | 
								if self._check_required_topics(topics_present=repo_topics[repo.id], topics_required=topics):
 | 
				
			||||||
				repos_keep.append(repo)
 | 
									repos_keep.append(repo)
 | 
				
			||||||
			else:
 | 
								else:
 | 
				
			||||||
				repos_reject.append(repo)
 | 
									repos_reject.append(repo)
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		self.__logger.info(f"Keeping the following repos because they contain all required topics ({topics}):")
 | 
							self.__logger.info("")
 | 
				
			||||||
 | 
							self.__logger.info(f"\nKeeping {len(repos_keep)} repos because they contain all required topics ({topics}):")
 | 
				
			||||||
		if len(repos_keep) > 0:
 | 
							if len(repos_keep) > 0:
 | 
				
			||||||
			for repo in repos_keep:
 | 
								for repo in repos_keep:
 | 
				
			||||||
				self.__logger.info(f"> {repo.full_name}")
 | 
									self.__logger.info(f"> {repo.full_name}")
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			self.__logger.info("> None")
 | 
								self.__logger.info("> None")
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		self.__logger.info("Rejecting the following repos because they don't contain all required topics:")
 | 
							self.__logger.info("")
 | 
				
			||||||
 | 
							self.__logger.info(f"Rejecting {len(repos_reject)} repos because they don't contain all required topics:")
 | 
				
			||||||
		if len(repos_reject) > 0:
 | 
							if len(repos_reject) > 0:
 | 
				
			||||||
			for repo in repos_reject:
 | 
								for repo in repos_reject:
 | 
				
			||||||
				self.__logger.info(f"> {repo.full_name} ({repo_topics[repo.id]})")
 | 
									self.__logger.info(f"> {repo.full_name} ({repo_topics[repo.id]})")
 | 
				
			||||||
@@ -267,7 +274,8 @@ class Migrator:
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		return repos_keep
 | 
							return repos_keep
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	def _check_required_topics(self, topics_present: list[str], topics_required: list[str]) -> bool:
 | 
						@staticmethod
 | 
				
			||||||
 | 
						def _check_required_topics(topics_present: list[str], topics_required: list[str]) -> bool:
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		for topic in topics_required:
 | 
							for topic in topics_required:
 | 
				
			||||||
			if topic not in topics_present:
 | 
								if topic not in topics_present:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user