Github Automation via Python

Satyam A
2 min readFeb 20, 2022

--

GitHub Automation — Part 1

Automation with Python (source : Google)

Hello Everyone !!

This is my first blog post, and I decided to start off by sharing about my automation task I have done recently.

Here you will learn complete Automation for Managing GitHub organisation in Python that will help to reduce repetitive task and to do work smartly.

First lets understand the requirement of this automation -

GitHub Organisations are shared accounts where businesses and open-source projects can collaborate across many projects at once, with sophisticated security and administrative features .

and managing these organisation is not easy specially when you have a lot of people to work around or you have a big team to manage so here comes the automation

now the question is What can we do with this automation !

  1. Adding Users to Organisation , Repositories , Teams
  2. Creating Teams, Repositories
  3. Adding Team to Repositories
  4. Creating Branch & Branch Protection Rule
  5. Adding Users to Branch & Branch Protection Rule

Yes !! this all can be done you just need to enter Username/Team name / Repository Name & one Enter. It can be done via Jenkins or from any server.

Requirements

Create a Personal Access Token from Github by referring this link.

PackagesPyGithub

Best practice to install a package is creating a virtual environment .

We are using python3 here…

creating a virtual environment

=> python3 -m venv virtual-env-name

activating the env

=> source virtual-env-name/bin/activate

installing a module

=> pip3 install PyGithub

creating a virtual environment , activating the environment & installing a module

For basic understanding of PyGithub you can refer the official document page link .

after setting things you need to check if GitHub Token is working for you & you have the required access.

from github import Githuborg_name = #org_nameUSERNAME = #username
access_token = #github_token
git_hub = Github(USERNAME, access_token)for repo in git_hub.get_user().get_repos():
print(repo.name)

you can find complete code here →

https://github.com/shinchan-02/python-github-script/blob/main/main.py

Thanks for reading ,Let me know if you like my content also if you want to add anything . Feel free to ask any question :)

#Github #python #Automation #DevOps

--

--

Satyam A
Satyam A

Written by Satyam A

DevOps | Engineer | Python ❤ | Automation | Learning and Sharing

No responses yet