
GitHub Webhook Commit Logger
April 1, 2025
GitHub Webhook Commit Logger
A Node.js server I built to track and log GitHub repository changes in detail. What makes this project unique is its ability to fetch and display actual file diffs from commits, something I was unable to find online for some reason.
What It Does
- Listens for GitHub push events via webhooks
- Logs detailed commit information including:
- Repository and branch details
- Pusher information
- Commit messages and metadata
- File changes (added, modified, removed)
- Full commit diffs fetched from GitHub API
How It Works
The server uses Express to handle incoming webhook requests and the GitHub REST API to fetch detailed commit information. Here's how it processes each push event:
app.post('/webhook', async (req, res) => {
const payload = req.body;
// Log basic push information
console.log('📥 Received a push event:');
console.log(`📝 Repo: ${payload.repository.full_name}`);
console.log(`🌿 Branch: ${payload.ref.replace('refs/heads/', '')}`);
// Process each commit in the push
for (const commit of payload.commits) {
// Log commit details
console.log(`🔸 Commit: ${commit.id}`);
console.log(`📝 Message: ${commit.message}`);
// Fetch and log the full diff
const diffText = await fetchCommitDiff(
payload.repository.full_name,
commit.id
);
console.log(`📝 Diff:\n${diffText}`);
}
});
Technical Bits
- Built with Node.js and Express
- Uses GitHub REST API for fetching commit diffs
- Implements secure webhook handling
- Supports environment-based configuration
- Includes detailed error handling and logging
Features
- Real-time Event Processing: Instantly processes GitHub push events
- Detailed Logging: Captures comprehensive commit information
- Diff Integration: Fetches and displays actual file changes
- Secure Authentication: Uses GitHub tokens for API access
- Error Handling: Robust error management and logging
Why I Built It
I created this project because I noticed a gap in existing tools - while many could track commits, none provided easy access to the actual file diffs in their webhook responses. This tool fills that need by fetching and displaying the complete changes made in each commit.
Future Ideas
- Add support for other GitHub events (PRs, issues)
- Implement a web interface for viewing logs
- Add filtering and search capabilities
- Support multiple repository tracking
- Add email/Slack notifications
- Implement log persistence
- Add rate limiting and security features