DEV Community

Cover image for Github API integration project /Automating Github
Kartik
Kartik

Posted on

Github API integration project /Automating Github

This project automates the process of retrieving and displaying user access information for any GitHub repository. By leveraging the GitHub API, this shell script can provide detailed insights into who has read, write, and admin access to a repository. This tool is particularly useful for DevOps engineers and project managers who need to audit repository access regularly.

How It Works

Setting Up: Start by exporting your GitHub username and personal access token as environment variables to keep them secure.

Running the Script: Execute the script with the desired repository owner and name as command line arguments.

Output Interpretation: The script uses the curl command to make API requests and jq to parse the JSON response, displaying users with specific access levels.

If you want to create the project, follow these detailed steps:

Step 1: Create a GitHub Organization and Repository
-Create a GitHub Organization:
-Go to GitHub.
-Click on your profile picture in the top-right corner and select "Your organizations."
-Click "New organization."
-Choose "Create a free organization" and fill in the required details such as organization name and email.

Create a Repository:
-Within your organization, click "New" to create a new repository.
-Name the repository and choose the visibility (public or private).

Step 2: Prepare Your Environment
-Install Required Tools:
Ensure you have curl installed. This tool will be used to make API requests.
-Install jq for parsing JSON data:
sudo apt install jq -y

Step 3: Write the Shell Script or clone it:
-Create the Shell Script :
Create a new shell script file, for example, list_users.sh.

Write the code from https://github.com/kartik-paliwa1/shell-script-for-API-integration/blob/main/list-users.sh

-Or you can directly clone it:
Write the below command to clone the repo.

git clone https://github.com/kartik-paliwa1/shell-script-for-API-integration

-Then open repo:
cd shell-script-for-API-integration

-Write your github user-name and your token:
export GITHUB_USERNAME="your_username"
export GITHUB_TOKEN="your_token"

Step 4: Execute the Script
-Set the File Permissions:
chmod 777 list_users.sh

-Run the Script:
Execute the script with your repository details:
./list_users.sh 'Organisation-name' 'Repo-name'

Step 5: Verify the Output:
The script should output the list of users with read access to the specified repository. For example:
Output:
kartik-paliwa1 has access to shell-script-for-API-integration

Credits: Learned this project from YT channel Abhishek.Veeramalla

Top comments (0)