🔗 DevOps Day 8 — Build a Beginner-Friendly GitHub API Project with Shell Scripting
🚀 Introduction
-
Fetch live GitHub data using an API
-
Parse results using a simple tool (
jq) -
Automate your report using a cron job
💡 What Is an API?
-
“How many ⭐ stars does this repo have?”
-
“How many open PRs or issues exist?”
GitHub’s API responds in JSON format — a lightweight data structure we can read easily with jq.
🧰 Prerequisites
Before we start:
-
Install curl and jq
curllets you talk to APIs, andjqhelps read JSON data. -
Know your GitHub repoExample:
-
Owner (user/org):
torvalds -
Repo name:
linux
-
-
(Optional) Add a GitHub Token for higher rate limits
(You can skip this for public repos.)
🧩 Step 1 — Create the Script
Create a file called github_report.sh and paste this code:
⚙️ Step 2 — Run the Script
Make it executable:
Then run:
Example output:
⏰ Step 3 — Automate with Cron
You can make this run daily and collect historical data.
Open the cron editor:
Add this line (runs every morning at 8 AM):
This keeps a growing CSV (github_stats.csv) — one line per day with your repo stats.
🔐 Step 4 — Best Practices
-
For private repos, you must use a GitHub token with
repo:readpermission. -
Keep your token secret (never upload it to GitHub).
-
You can extend the script to show:
-
Last 5 commits
-
Latest workflow run status
-
Top contributors
-
🌟 Summary
You just built your first DevOps automation with an API using shell scripting!
What you learned today:
-
How to make API calls using
curl -
How to read JSON data with
jq -
How to save and schedule data collection with cron
“APIs + Shell scripting = endless automation possibilities.”
Comments
Post a Comment