Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub API DevOps Project

Automate checking who has access to GitHub repositories using shell scripting and GitHub API.


What This Project Does

Problem: When an employee leaves, you need to check 50+ repositories manually to see if they have access. Takes 1 hour.

Solution: This script checks all repositories automatically in 2 minutes.


Project Files (Only 4 Files!)

├── README.md                    (This file - complete guide)
├── LEARN_BASH_BASICS.md        (Learn bash symbols and concepts)
├── list-users.sh               (Main script)
└── test-connection.sh          (Test script)

Quick Start (3 Steps)

Step 1: Create GitHub Token

  1. Go to: https://github.com/settings/tokens
  2. Click "Generate new token (classic)"
  3. Name: DevOps API
  4. Check boxes: repo and read:org
  5. Click "Generate token"
  6. Copy the token (starts with ghp_)

Step 2: Create Test Repository

  1. Go to: https://github.com/new
  2. Name: test-repo
  3. Make it Public
  4. Check "Add a README file"
  5. Click "Create repository"

Step 3: Run the Script

# Install tools (Ubuntu/EC2)
sudo apt update
sudo apt install curl jq -y

# Make scripts executable
chmod +x *.sh

# Set credentials (replace with YOUR values)
export username=YOUR_GITHUB_USERNAME
export token=ghp_YOUR_TOKEN

# Test connection
./test-connection.sh

# Run main script
./list-users.sh YOUR_USERNAME test-repo

Expected Output

When you run: ./test-connection.sh

========================================
Testing GitHub API Connection
========================================

✓ Credentials are set
  Username: Pavan143Kundeti
  Token: ghp_abc123...

✓ Connecting to GitHub API...

✓ Connection successful!

Your GitHub Info:
  Username: Pavan143Kundeti
  Name: Pavan Kundeti
  Public Repos: 5

✓ You're ready to use the main script!

When you run: ./list-users.sh Pavan143Kundeti test-repo

========================================
GitHub Repository Access Checker
========================================

Fetching users with access to: Pavan143Kundeti/test-repo

Users with access:
------------------
Pavan143Kundeti
alice
bob

Total users: 3

========================================

How It Works (Simple Explanation)

  1. You run the script with repository name
  2. Script calls GitHub API using your token
  3. GitHub sends back JSON data with user list
  4. Script extracts usernames using jq
  5. Script displays results

Behind the scenes:

# Script does this:
curl -u "username:token" https://api.github.com/repos/owner/repo/collaborators

# GitHub returns JSON:
[{"login": "Pavan143Kundeti"}, {"login": "alice"}]

# Script extracts usernames:
Pavan143Kundeti
alice

Troubleshooting

Error: Permission denied

chmod +x *.sh

Error: jq: command not found

sudo apt install jq -y

Error: Bad credentials

# Check your token
echo $token
# If empty, set it again
export token=ghp_YOUR_TOKEN

Error: Credentials not set

export username=YOUR_USERNAME
export token=ghp_YOUR_TOKEN

Real-World Usage

Check if Bob has access

./list-users.sh mycompany payment-service | grep bob

Create audit report

echo "Audit Report - $(date)" > audit.txt
./list-users.sh mycompany payment-service >> audit.txt
./list-users.sh mycompany user-service >> audit.txt
cat audit.txt

Understanding the Code

Read LEARN_BASH_BASICS.md to understand every symbol and concept used in the scripts.

Topics covered:

  • Variables ($name, ${name})
  • Tests ([ -z "$var" ], [ $a -gt $b ])
  • Logic (|| OR, && AND)
  • Arguments ($1, $2, $#)
  • Paths (., .., ~, /)
  • Pipes (|)
  • Redirects (>, >>)
  • curl flags (-s, -u)
  • Command substitution ($(command))

What You Learned

✅ GitHub Personal Access Tokens ✅ REST API calls with curl ✅ JSON parsing with jq ✅ Shell scripting automation ✅ Error handling ✅ Real DevOps use case


Security

⚠️ Never commit your token to Git ⚠️ Never share your token ⚠️ Rotate tokens every 90 days ⚠️ Use environment variables only


Quick Commands

# Setup
sudo apt install curl jq -y
chmod +x *.sh
export username=YOUR_USERNAME
export token=ghp_YOUR_TOKEN

# Run
./test-connection.sh
./list-users.sh YOUR_USERNAME test-repo

# Check credentials
echo $username
echo $token

Time to Complete: 15-30 minutes
Difficulty: Beginner-Friendly
Skills: Shell scripting, APIs, JSON, DevOps

🎉 Congratulations! You've completed a real DevOps automation project!

About

DevOps project to automate GitHub repository access checking using shell scripting and GitHub API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages