Building a GitHub Activity CLI - A Ruby Journey

Senior Software Engineer with 12 years of expertise in Ruby on Rails and Vue.js, specializing in health, e-commerce, staffing, and transport. Experienced in software development and version analysis.
Search for a command to run...

Senior Software Engineer with 12 years of expertise in Ruby on Rails and Vue.js, specializing in health, e-commerce, staffing, and transport. Experienced in software development and version analysis.
No comments yet. Be the first to comment.
In this series, I will present my portfolio projects that I developed using OpenSource code, along with usage guides.
Links RubyGems.org → https://rubygems.org/gems/task_tracker_cli GitHub Repo → https://github.com/sulmanweb/task_tracker_cli Roadmap.sh Task → https://roadmap.sh/projects/task-tracker My Solution for UpVotes → https://roadmap.sh/projects/task-trac...
Motivation After building several Shopify embedded apps, I've learned valuable lessons about what works (and what definitely doesn't) in the embedded app environment. Today, I'm sharing these insights to help you avoid common pitfalls and build bette...

As a developer working with Shopify's ecosystem, I recently built a multi-tenant SaaS application that synchronizes customer data between Shopify stores and external services. In this article, I'll share my experience and technical insights into crea...

As developers, we're always looking for ways to streamline our deployment process while maintaining security and reliability. Today, I'm excited to share my experience setting up an automated deployment pipeline for a Rails application using Dokku an...

The Challenge: Modernizing Rails Deployment When I recently needed to deploy my Rails 8 application with multiple databases, I faced a common dilemma: choosing between expensive managed solutions and complex self-managed servers. My requirements were...

The Cost-Benefit Realization As a Rails developer who recently migrated from Heroku to Dokku, I want to share my journey and the surprising benefits I discovered. This transition wasn't just about cost savings—it opened up new possibilities for my de...

GitHub Repo → https://github.com/sulmanweb/github-activity-cli
Roadmap.sh Task → https://roadmap.sh/projects/github-user-activity
My Solution for UpVotes → https://roadmap.sh/projects/github-user-activity/solutions?u=67124acb791f57dd60b7e0e4
Have you ever wanted to quickly check someone's GitHub activity right from your terminal? I recently took on this challenge by building a simple yet powerful CLI tool in Ruby. Let me walk you through how I built this GitHub Activity CLI, sharing both the technical details and lessons learned along the way.
The GitHub Activity CLI is a command-line tool that fetches and displays a user's recent GitHub activities. It's built with Ruby and follows clean code principles while keeping the implementation straightforward and maintainable.
The project requirements came from roadmap.sh's GitHub User Activity project. The main goals were to:
Fetch a user's recent GitHub activities using the GitHub API
Display the activities in a readable format
Handle various types of GitHub events (pushes, issues, PRs, etc.)
Implement proper error handling
I organized the code into a clean, modular structure:
├── bin
│ └── github-activity # Executable CLI script
└── lib
├── activity_formatter.rb # Formats different event types
├── github_activity.rb # Main application logic
└── github_client.rb # Handles GitHub API communication
The heart of the application is the GitHubClient class that handles all API communications:
class GitHubClient
BASE_URL = 'https://api.github.com'
def fetch_user_events(username)
uri = URI("#{BASE_URL}/users/#{username}/events")
response = make_request(uri)
case response
when Net::HTTPSuccess
JSON.parse(response.body)
when Net::HTTPNotFound
raise "User '#{username}' not found"
else
raise "Failed to fetch GitHub activity: #{response.message}"
end
end
end
I used Ruby's built-in Net::HTTP library to keep dependencies minimal. The client handles basic error cases and returns parsed JSON data.
One of the interesting challenges was formatting different types of GitHub events. I created a dedicated ActivityFormatter class that handles this using a clean pattern:
class ActivityFormatter
def format(event)
case event['type']
when 'PushEvent'
format_push_event(event)
when 'CreateEvent'
format_create_event(event)
when 'IssuesEvent'
format_issues_event(event)
# ... other event types
end
end
end
This approach makes it easy to add support for new event types and keeps the formatting logic organized.
The GitHubActivity class ties everything together:
class GitHubActivity
def initialize(username)
@username = username
@client = GitHubClient.new
@formatter = ActivityFormatter.new
end
def run
events = @client.fetch_user_events(@username)
if events.empty?
puts "No recent activity found for user '#{@username}'"
return
end
display_events(events)
end
end
I focused on making the CLI intuitive and user-friendly. Users can simply run:
./bin/github-activity username
The output is clean and readable:
Recent GitHub activity for sulmanweb:
--------------------------------------------------
Pushed 2 commits to sulmanweb/project
Created branch in sulmanweb/new-repo
Closed issue 'Bug fix needed' in sulmanweb/app
Building this CLI taught me several valuable lessons:
API Integration: Working with the GitHub API showed me the importance of good error handling and response parsing.
Code Organization: Breaking the functionality into separate classes made the code more maintainable and testable.
User Experience: Even for a CLI tool, user experience matters. Clear output and helpful error messages make a big difference.
Want to help make the GitHub Activity CLI even better? There are several ways you can contribute:
⭐ Star the repository to show your support
💝 Consider upvoting my solution at GitHub Activity CLI solution page
🎁 Share the project with your network
🐛 Report bugs and suggest features through GitHub Issues
🔧 Submit pull requests for bug fixes or enhancements
📚 Help improve the documentation
🌐 Help with translations if you speak multiple languages
While the current version works well, there's always room for improvement:
Add authentication to handle API rate limits
Include more detailed event information
Add filtering options for specific event types
Implement caching for faster repeated queries
Want to try it out? Here's how:
Clone the repository
Make the CLI executable: chmod +x bin/github-activity
Run it: ./bin/github-activity <username>
Building this GitHub Activity CLI was a great exercise in creating a focused, useful tool while maintaining clean code practices. It shows how a relatively simple idea can be turned into a practical utility that others can use and build upon.
The source code is available on GitHub, and I welcome any feedback or contributions from the community. Happy coding! 🚀