Overview
Diffy uses a GitHub App to access pull requests, receive webhooks, and interact with repositories. This guide walks you through creating and configuring your GitHub App.Prerequisites
- A GitHub account with organization or repository admin access
- Node.js 18+ installed
- Diffy API running locally or deployed
Creating a GitHub App
Navigate to GitHub Developer Settings
Go to GitHub Settings → Developer settings → GitHub Apps → New GitHub AppOr visit directly: https://github.com/settings/apps/new
Configure Basic Information
Fill in the basic app information:
- GitHub App name:
Diffy(or your preferred name) - Homepage URL:
https://yourdomain.com - Callback URL:
https://api.yourdomain.com/auth/callback - Setup URL: Leave blank
- Webhook URL:
https://api.yourdomain.com/github/webhook - Webhook secret: Generate a strong random string (save this!)
Set Repository Permissions
Configure the following permissions:
| Permission | Access Level | Purpose |
|---|---|---|
| Pull requests | Read & Write | Access PR data and diffs |
| Contents | Read-only | Read repository content |
| Metadata | Read-only | Access repository metadata |
Subscribe to Events
Enable these webhook events:
- ☑️ Installation - Track app installations
- ☑️ Pull request - Receive PR notifications
Generate a Private Key
After creating the app:
- Scroll down to Private keys
- Click Generate a private key
- Save the downloaded
.pemfile securely - Convert to base64 for environment variable:
Environment Configuration
Add these variables to your.env file:
.env
GitHub Service Implementation
The GitHub service initializes the Octokit App client with your credentials:github.service.ts
Installing the GitHub App
Get Installation URL
Users need to install your GitHub App to their account or organization:Direct users to:
https://api.yourdomain.com/github/installSelect Repositories
On the installation page, users can choose:
- All repositories - Grant access to all current and future repos
- Only select repositories - Choose specific repositories
Creating Installation Tokens
Use installation tokens to make authenticated requests to GitHub:Installation tokens expire after 1 hour. The Octokit library handles token refresh automatically.
Accessing Pull Requests
Once installed, you can access pull request data:Getting PR Diffs
Fetch the diff content for a pull request:API Endpoints
These endpoints are available after GitHub App setup:Get Installation URL
Get Pull Request
Get PR Diff
Listing Installations
List all app installations for monitoring:Troubleshooting
”Bad credentials” error
- Verify your App ID is correct
- Check that the private key is properly base64 encoded
- Ensure the private key hasn’t expired or been revoked
Webhook not receiving events
- Verify the webhook URL is publicly accessible
- Check that the webhook secret matches your configuration
- Review webhook delivery logs in GitHub App settings
”Resource not accessible” error
- Ensure the GitHub App is installed to the target repository
- Verify the app has the required permissions
- Check that the user’s installation ID is correctly stored
Security Best Practices
Next Steps
- Learn how to handle GitHub Webhooks
- Set up WebSocket real-time updates
- Explore the GitHub API endpoints