Git Product home page Git Product logo

devwithkrishna / list-repos-in-organization-based-on-name-and-add-to-github-teams Goto Github PK

View Code? Open in Web Editor NEW
1.0 0.0 0.0 48 KB

list-repos-in-organization-based-on-name-and-add-to-github-teams

Home Page: https://github.com/devwithkrishna/list-repos-in-organization-based-on-name-and-add-to-github-teams

License: MIT License

Python 100.00%
github github-teams rest-api github-action python

list-repos-in-organization-based-on-name-and-add-to-github-teams's Introduction

list-repos-in-organization-based-on-name-and-add-to-github-teams

list-repos-in-organization-based-on-name-and-add-to-github-teams

JIRA LINK

This is associated with the JIRA story DEVOPS-39

DESCRIPTION

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.

Here's a high-level overview of the program:

Function Definitions:

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.

Main Function:

The main function parses command-line arguments (org_name, github_team_name, search_string, permission) using the argparse module. It then calls the list_repos_and_add_to_github_teams function with the parsed arguments.

GitHub API Calls:

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.

Pagination:

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.

Error Handling:

The program checks the status code of the API response and prints an error message if the request fails. 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.

Program Inputs

The program requires 4 Inputs which are passed as inputs on GitHub workflow

  • org_name --> GitHub Organization name
  • github_team_name --> GithHub team name
  • search_string --> GitHub repo name search string
  • permission --> Permissions for Github teams across repository admin,push,pull,maintain,triage
    pipenv run python3 list_repos_and_add_to_teams.py --org_name ${{ inputs.org_name }} \
          --github_team_name ${{ inputs.github_team_name }} --search_string ${{ inputs.search_string }} \
          --permission ${{ inputs.permission }}

Note

This Program uses Personal Access token for Github authentication and passed as a environment variable in GitHub Workflow from GitHub Secrets.

list-repos-in-organization-based-on-name-and-add-to-github-teams's People

Contributors

dependabot[bot] avatar githubofkrishnadhas avatar

Stargazers

 avatar

list-repos-in-organization-based-on-name-and-add-to-github-teams's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.