GitHub automation to add all repos to a specific team across GitHub org
- Security team may need to monitor all repos
- core team need to be added as a reviewer for PP's, so they need to add the teams to repos
-
This repository contains code to add all repositories in a github organization to a specific github teams
-
Uses Github REST API along with python.
-
This will add all repos in organization to the team thats specfied returning 204 status code.
The program makes several API calls to the GitHub API using the requests module to list repositories, list teams, and add repositories to teams. It uses the Authorization header with a GitHub token (os.getenv('GH_TOKEN')) for authentication.
The program requires 3 Inputs which are passed as inputs
- organization --> GitHub Organization name
- github_team_name --> GithHub team name
- permission --> Permissions for Github teams across repository
admin
,push
,pull
,maintain
,triage
GH_TOKEN="<your github token here>"
- clone the repository to your local
- Change directory to the cloned repository
- set up the .env file and pass the auth token there.
- Run
python3 add_repos_to_gh_teams.py --organization <organization name> --github_team_name <github team name> --permission <permission required>
Note
This Program uses Personal Access token for GitHub authentication On local testing python-dotenv with .env file is used On GitHub Workflow, passed as a environment variable in from GitHub Secrets.