def teams_to_string(repository:Repository, exclude, others='') -> str: """Convert team list to a single string """ teams = '' t:Team for t in repository.get_teams(): matched = ( t.name.lower() == exclude.lower() ) within = ( t.name.lower() in others.lower() ) if matched is False and within is False: teams = f"{t.name}, {teams}" return teams.strip(", ")
def check_team_added_already(team_name: str, repository: Repository.Repository) -> bool: """Check if a GitHub organisation team already exists in a GitHub repository. Args: team_name: A GitHub organisation team name. repository: A ``github.Repository.Repository`` object of the GitHub repository of interest. Returns: True/False depending on whether ``team_name`` exists as the name of a GitHub organisation team within the GitHub repository ``repository``. """ return team_name in extract_attribute_from_paginated_list_elements( repository.get_teams(), "name")
def diff_team_access( self, repo: Repository, access_config: Dict[str, Dict[str, Union[Policy[Any], List[str]]]] ) -> List[Change[str]]: repo_teams = cache.lazy_get_or_store( "repoteams_%s" % repo.name, lambda: list(repo.get_teams())) # type: List[GithubTeam] current_perms = { "pull": set([t.name for t in repo_teams if t.permission == "pull"]), "push": set([t.name for t in repo_teams if t.permission == "push"]), "admin": set([t.name for t in repo_teams if t.permission == "admin"]) } ret = [] # type: List[Change[str]] default_pol = access_config.get("policy", OVERWRITE) for role in current_perms.keys(): pol = cast(Policy[str], access_config.get(role, {}).get("policy", default_pol)) tname_changes = pol.apply_to_set( meta=ChangeMetadata( executor=self.apply_team_access, params=[ repo, role, ], ), current=current_perms[role], plan=set( cast(List[str], access_config.get(role, {}).get("teams", []))), cosmetic_prefix="%s:" % role) ret += cast(List[Change[str]], tname_changes) return ret
def assert_baseline(repo: Repository): team_data = list(repo.get_teams()) check_data = {team["name"]: team for team in BASELINE} compare_team_permissions(actual=team_data, expected=check_data)