def add_team_with_permissions_to_repository( team: Team.Team, permission: str, repository: Repository.Repository) -> None: """Add a team to a GitHub repository if it isn't already added, and set its permission level. Args: team: A ``github.Team.Team`` object containing the GitHub organisation team to add to the repository with set permissions. permission: A permission level to provide the ``team`` within ``repository``. See the GitHub API documentation_ for possible options. repository: A ``github.Repository.Repository`` object containing the GitHub organisation repository of interest. Returns: None. ``repository`` will have ``team`` with ``permission`` access to it. .. _documentation: https://docs.github.com/en/free-pro-team@latest/rest/reference/teams#add-or-update-team-repository-permissions """ # Check if the team already exists in the repository - if not, add the team to the repository if not check_team_added_already(team.name, repository): team.add_to_repos(repository) # Set the team repository permission to permission team.set_repo_permission(repository, permission)
def repositories(team: Team.Team, filter_function: Callable = None) -> tuple: """Return all repos into a standard list """ Out.group_start("Fetching all repositories") RateLimiter.check() remote_repos = team.get_repos() # return 3 elements, everything, those that match filter, those that fail filter all_list: list(Repository.Repository) = [] filtered_list: list(Repository.Repository) = [] failed_filter_list: list(Repository.Repository) = [] archived_list: list(Repository.Repository) = [] i: int = 0 total: int = remote_repos.totalCount for repo in remote_repos: i = i + 1 RateLimiter.check() Out.log(f"[{i}/{total}] Repo [{repo.full_name}]") all_list.append(repo) # filter our archived ones if repo.archived is True: archived_list.append(repo) elif filter_function is not None: match = filter_function(repo) if match: filtered_list.append(repo) else: failed_filter_list.append(repo) Out.group_end() return all_list, filtered_list, failed_filter_list, archived_list
def test_admin_role(self, wsgi): body = {'username': fake.word(), 'password': fake.word()} with patch('github.AuthenticatedUser.AuthenticatedUser' ) as github_user_mock: github_user = github_user_mock.return_value github_user.create_authorization.return_value = Authorization( None, [], {"token": "123456789"}, completed=True) github_user.login = '******' admin_team = Team(None, [], {"name": "sandwich-admin"}, completed=True) admin_team.has_in_members = MagicMock(return_value=True) org = Organization(None, [], {"login": "******"}, completed=True) org.get_teams = MagicMock(return_value=[admin_team]) github_user.get_orgs.return_value = [org] self.post(wsgi, '/v1/auth/github/authorization', body=body)
def create_team(org, name, description, repo_names=[]): # PyGithub creates secret teams, and has no way of turning that off! :( post_parameters = { "name": name, "description": description, "privacy": "closed", "permission": "push", "repo_names": repo_names } headers, data = org._requester.requestJsonAndCheck("POST", org.url + "/teams", input=post_parameters) return Team(org._requester, headers, data, completed=True)
def from_githubteam( ght: GithubTeam, *, retrieve_subteams: bool = False, team_policy: Optional[Policy['Team']] = None, member_policy: Optional[Policy['BaseMember']] = None) -> 'Team': ret = Team( ght.name, description=ght.description, id=ght.id, privacy=ght.privacy, default_permission=ght.permission, slug=ght.slug, ) if team_policy: ret.team_policy = team_policy if member_policy: ret.member_policy = member_policy for m in cache.lazy_get_or_store( "teammembers_%s" % ght.name, lambda: list(ght.get_members("member"))): ret.add_member(Member(username=m.login, id=m.id)) for m in cache.lazy_get_or_store( "teammaintainers_%s" % ght.name, lambda: list(ght.get_members("maintainer"))): ret.add_member(Maintainer(username=m.login, id=m.id)) if retrieve_subteams: for subteam in cache.lazy_get_or_store( "subteams_%s" % ght.name, lambda: list(ght.get_subteams())): ret.subteams.add(Team.from_githubteam(subteam)) return ret