@@ -52,6 +52,7 @@ class GHorg: # pylint: disable=too-many-instance-attributes, too-many-lines
5252 current_repos_collaborators : dict [Repository , dict [str , str ]] = field (default_factory = dict )
5353 configured_repos_collaborators : dict [str , dict [str , str ]] = field (default_factory = dict )
5454 archived_repos : list [Repository ] = field (default_factory = list )
55+ unconfigured_teams : list [Team ] = field (default_factory = list )
5556 unconfigured_team_repo_permissions : dict [str , dict [str , str ]] = field (default_factory = dict )
5657 stats : OrgChanges = field (default_factory = OrgChanges )
5758
@@ -603,31 +604,38 @@ def sync_teams_members(self, dry: bool = False) -> None: # pylint: disable=too-
603604 team .name ,
604605 )
605606
606- def get_unconfigured_teams (
607+ def get_and_delete_unconfigured_teams (
607608 self , dry : bool = False , delete_unconfigured_teams : bool = False
608609 ) -> None :
609610 """Get all teams that are not configured locally and optionally remove them"""
610611 # Get all teams that are not configured locally
611- unconfigured_teams : list [Team ] = []
612612 for team in self .current_teams :
613613 if team .name not in self .configured_teams :
614- unconfigured_teams .append (team )
614+ self . unconfigured_teams .append (team )
615615
616- if unconfigured_teams :
616+ if self . unconfigured_teams :
617617 if delete_unconfigured_teams :
618- for team in unconfigured_teams :
618+ for team in self . unconfigured_teams :
619619 logging .info ("Deleting team '%s' as it is not configured locally" , team .name )
620620 self .stats .delete_team (team = team .name , deleted = True )
621621 if not dry :
622- team .delete ()
622+ try :
623+ team .delete ()
624+ except UnknownObjectException as e :
625+ logging .info (
626+ "Team '%s' could not be deleted, probably because it was already "
627+ "deleted as part of a parent team. "
628+ "Error: %s" ,
629+ team .name ,
630+ e ,
631+ )
623632 else :
624- unconfigured_teams_str = [team .name for team in unconfigured_teams ]
625633 logging .warning (
626634 "The following teams of your GitHub organisation are not "
627635 "configured locally: %s. Taking no action about these teams." ,
628- ", " .join (unconfigured_teams_str ),
636+ ", " .join ([ team . name for team in self . unconfigured_teams ] ),
629637 )
630- for team in unconfigured_teams :
638+ for team in self . unconfigured_teams :
631639 self .stats .delete_team (team = team .name , deleted = False )
632640
633641 def get_members_without_team (
0 commit comments