Last active
January 25, 2022 00:09
-
-
Save SemVerTsar/4260a186b8ba9254a597 to your computer and use it in GitHub Desktop.
Using GitHub's API to manage a team's access to repos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# http://pygithub3.readthedocs.org/en/latest/ | |
# Pip install pygithub3 | |
from pygithub3 import Github | |
token = '<your GitHub application token>' | |
# Teams | |
team_list = gh.orgs.teams.list('<organisation name>') | |
for team in team_list.iterator(): | |
print team.name, team.id # Select the teams you want to add repos to, You only need the ID | |
team_owners = 00000 # The ID of your owners team | |
teams = [<team1>, <team2>, <team3>] | |
# Repos | |
repos = gh.orgs.teams.list_repos(team_owners) # Getting all repos owned by the organisation | |
# Adding Repos to teams | |
for team in teams: | |
for repo in repos.iterator(): | |
gh.orgs.teams.add_repo(team, '<organisation name>',repo.name) | |
# Members, getting an organisation's members | |
members = gh.orgs.members.list('<organisation name>') | |
for member in members.iterator(): | |
print member.login | |
# I use this to update our teams access to repos. | |
# Adding them manually each time is a pain, this is run daily in a cron job | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment