Skip to content

Commit d29d403

Browse files
DEVOPS-64 add-all-github-organization-repos-to-a-github-team initial commit
1 parent c92e80c commit d29d403

File tree

8 files changed

+433
-1
lines changed

8 files changed

+433
-1
lines changed

.github/dependabot.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "pip"
4+
directory: /
5+
schedule:
6+
interval: weekly
7+
# Assignees to set on pull requests
8+
assignees:
9+
- "githubofkrishnadhas"
10+
# prefix specifies a prefix for all commit messages. When you specify a prefix for commit messages,
11+
# GitHub will automatically add a colon between the defined prefix and the commit message provided the
12+
# defined prefix ends with a letter, number, closing parenthesis, or closing bracket.
13+
commit-message:
14+
prefix: "dependabot python package"
15+
# Use reviewers to specify individual reviewers or teams of reviewers for all pull requests raised for a package manager.
16+
# reviewers:
17+
# - "devwithkrishna/admin"
18+
# Raise pull requests for version updates to pip against the `main` branch
19+
target-branch: "main"
20+
# Labels on pull requests for version updates only
21+
labels:
22+
- "pip"
23+
- "dependancies"
24+
# Increase the version requirements for Composer only when required
25+
versioning-strategy: increase-if-necessary
26+
# Dependabot opens a maximum of five pull requests for version updates. Once there are five open pull requests from Dependabot,
27+
# Dependabot will not open any new requests until some of those open requests are merged or closed.
28+
# Use open-pull-requests-limit to change this limit.
29+
open-pull-requests-limit: 10
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: add-all-github-organization-repos-to-a-github-team
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
organization:
6+
description: 'GitHub organization name'
7+
type: string
8+
required: true
9+
github_team_name:
10+
description: 'GithHub team name'
11+
type: string
12+
required: true
13+
permission:
14+
required: true
15+
description: 'Permissions for Github teams across repository'
16+
type: choice
17+
options:
18+
- admin
19+
- push
20+
- pull
21+
- triage
22+
- maintain
23+
24+
jobs:
25+
add-all-github-organization-repos-to-a-github-team:
26+
runs-on: ubuntu-latest
27+
env:
28+
GH_TOKEN: ${{ secrets.DEVWITHKRISHNA_PERSONAL_ACCESS_TOKEN }}
29+
steps:
30+
- name: Git checkout
31+
uses: actions/checkout@v4
32+
- name: set up python
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: '3.10'
36+
- name: Pipenv venv installation
37+
run: |
38+
pip install pipenv
39+
pipenv install --skip-lock
40+
- name: Execute python program
41+
run: |
42+
pipenv run python3 add_repos_to_gh_teams.py --organization ${{ inputs.organization }} \
43+
--github_team_name ${{ inputs.github_team_name }} --permission ${{ inputs.permission }}
44+
- name: program execution completed
45+
run: echo "program execution completed"
46+

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,4 @@ cython_debug/
157157
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160-
#.idea/
160+
.idea/

Pipfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
requests = "==2.31.0"
8+
argparse = "=1.4.0"
9+
python-dotenv = "=1.0.1"
10+
11+
12+
[requires]
13+
python_version = "3"

Pipfile.lock

Lines changed: 167 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,44 @@
11
# automation-to-add-all-repos-to-a-github-teams
22
GitHub automation to add all repos to a specific team across GitHub org
3+
4+
# use case
5+
* Security team may need to monitor all repos
6+
* core team need to be added as a reviewer for PP's, so they need to add the teams to repos
7+
8+
# How code works
9+
10+
* This repository contains code to add all repositories in a github organization to a specific github teams
11+
12+
* Uses Github REST API along with python.
13+
14+
* This will add all repos in organization to the team thats specfied returning 204 status code.
15+
16+
17+
## GitHub API Calls
18+
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.
19+
20+
# Program Inputs
21+
22+
The program requires 3 Inputs which are passed as inputs
23+
24+
* organization --> GitHub Organization name
25+
* github_team_name --> GithHub team name
26+
* permission --> Permissions for Github teams across repository `admin`,`push`,`pull`,`maintain`,`triage`
27+
28+
# dot env file
29+
30+
```markdown
31+
GH_TOKEN="<your github token here>"
32+
```
33+
34+
# Run code in local
35+
1. clone the repository to your local
36+
2. Change directory to the cloned repository
37+
3. set up the .env file and pass the auth token there.
38+
4. Run `python3 add_repos_to_gh_teams.py --organization <organization name> --github_team_name <github team name> --permission <permission required>`
39+
40+
41+
>[!NOTE]
42+
> This Program uses Personal Access token for GitHub authentication
43+
> On local testing python-dotenv with .env file is used
44+
> On GitHub Workflow, passed as a environment variable in from GitHub Secrets.

0 commit comments

Comments
 (0)