2

I am using the below snippet to add the repos to an existing team "ADMIN" and then to change the permissions of all the repos to 'Admin'.

from github import **Github**

def teams_permissions(pat):
    print("")
    admin = 'ADMIN'
    for teams in g.get_organization(org_name).get_teams():
        for repo in g.get_organization(org_name).get_repos():
            if(teams.name != None and admin in teams.name):
                value = teams.update_team_repository(repo, 'admin')
                teams.add_to_repos(repo)
                print(value)
                print(teams.get_repo_permission(repo))
Output:

True
Permissions(triage=False, push=False, pull=True, maintain=False, admin=False)

The return of "teams.update_team_repository(repo, 'admin')" is True but then the "teams.get_repo_permission(repo)" returns as pull=True i.e. it still has the Read permission. The same is confirmed from the GUI.

Am I missing something here?

raiv
  • 21
  • 1

2 Answers2

0

I think add_to_repos should be called before update_team_repository

riemann
  • 435
  • 4
  • 12
0

Yes, the team should be added to repository, if not added before. I did encounter a problem while assigning permission [read/write] to Team after adding it to Repository. As per pygithub Documentation, [pull/push] should be used respectively to assign [Read/Write]. Whereas admin, maintain, and triage can be passed without any change.

# add Team to Repository and assign write permission
repo = gitInstance.get_organization(ORGANIZATION_NAME).get_repo("repoName")
team =get_organization(ORGANIZATION_NAME).get_team_by_slug("teamName")
team.add_to_repos(repo)
team.update_team_repository(repo, "push")