Skip to content

Commit 8369599

Browse files
DEVOPS-39 Updated README
1 parent ef4eb8e commit 8369599

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,53 @@
11
# list-repos-in-organization-based-on-name-and-add-to-github-teams
22
list-repos-in-organization-based-on-name-and-add-to-github-teams
3+
4+
# JIRA LINK
5+
This is associated with the JIRA story [DEVOPS-39](https://devwithkrishna.atlassian.net/browse/DEVOPS-39)
6+
7+
# DESCRIPTION
8+
9+
This Python program uses the GitHub API to list repositories under a specified organization, filter repositories based on a search string in their names, and add the matching repositories to a specified GitHub team with a specified permission level.
10+
11+
## Here's a high-level overview of the program:
12+
13+
## Function Definitions:
14+
15+
list_repos_and_add_to_github_teams: This function takes the organization name (org_name), GitHub team name (github_team_name), search string (search_string), and permission level (permission) as input. It lists all repositories under the organization, filters them based on the search string, and adds the matching repositories to the specified GitHub team with the specified permission level.
16+
17+
### Main Function:
18+
19+
The main function parses command-line arguments (org_name, github_team_name, search_string, permission) using the argparse module.
20+
It then calls the list_repos_and_add_to_github_teams function with the parsed arguments.
21+
22+
### GitHub API Calls:
23+
24+
The program makes several API calls to the GitHub API using the requests module to list repositories, list teams, and add repositories to teams.
25+
It uses the Authorization header with a GitHub token (os.getenv('GH_TOKEN')) for authentication.
26+
27+
### Pagination:
28+
29+
The program handles pagination for listing repositories and teams by incrementing the page parameter in the API request until all repositories or teams are listed.
30+
31+
### Error Handling:
32+
33+
The program checks the status code of the API response and prints an error message if the request fails.
34+
Overall, this program provides a convenient way to automate the process of adding specific repositories to GitHub teams based on a search string in their names, with customizable permission levels.
35+
36+
# Program Inputs
37+
38+
The program requires 4 Inputs which are passed as inputs on GitHub workflow
39+
40+
* org_name --> GitHub Organization name
41+
* github_team_name --> GithHub team name
42+
* search_string --> GitHub repo name search string
43+
* permission --> Permissions for Github teams across repository `admin`,`push`,`pull`,`maintain`,`triage`
44+
45+
```
46+
pipenv run python3 list_repos_and_add_to_teams.py --org_name ${{ inputs.org_name }} \
47+
--github_team_name ${{ inputs.github_team_name }} --search_string ${{ inputs.search_string }} \
48+
--permission ${{ inputs.permission }}
49+
```
50+
51+
>[!NOTE]
52+
> This Program uses Personal Access token for Github authentication and passed as a environment variable in
53+
> GitHub Workflow from GitHub Secrets.

0 commit comments

Comments
 (0)