GitHub Automation — Part 1
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 !
- Adding Users to Organisation , Repositories , Teams
- Creating Teams, Repositories
- Adding Team to Repositories
- Creating Branch & Branch Protection Rule
- 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.
Packages — PyGithub
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
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_tokengit_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