This Express server provides APIs for integrating with GitHub Apps and OAuth Apps, including functionality to calculate git diffs between branches.
-
Copy
.env.exampleto.envand fill in your configuration:cp .env.example .env
-
Install dependencies:
npm install
-
Place your GitHub App private key in the root directory as
private.pem -
Start the server:
npm start
Unlike traditional webhook-based installations, this server provides manual authentication endpoints:
GET /app/auth
This returns an installation URL that users can visit to install your GitHub App:
{
"message": "Visit the installation URL to authenticate and install the GitHub App",
"installation_url": "https://github.com/apps/your-app-name/installations/new?state=abc123",
"state": "abc123",
"instructions": "After installation, you will be redirected to the callback URL"
}GET /app/callback?installation_id=123&setup_action=install&state=abc123
This endpoint is called automatically after the user installs your app. It:
- Fetches installation details
- Retrieves accessible repositories
- Stores the data in your JSON database
POST /app/refresh
Manually refresh all installations and repositories for your GitHub App.
GET /auth/github
Redirects users to GitHub for OAuth authorization.
GET /auth/github/callback?code=abc123&state=xyz789
Exchanges the authorization code for an access token and stores user data.
GET /auth/user/:userId
Retrieve stored user information (without the access token).
POST /diff/app
Content-Type: application/json
{
"repo_owner": "username",
"repo_name": "repository",
"base_branch": "main",
"head_branch": "feature-branch",
"installation_id": "123456"
}
POST /diff/oauth
Content-Type: application/json
{
"repo_owner": "username",
"repo_name": "repository",
"base_branch": "main",
"head_branch": "feature-branch",
"user_id": "12345"
}
Both endpoints return detailed diff information including:
- File changes
- Commit details
- Statistics (additions, deletions, modifications)
- Patch data
The server uses a JSON file (db.json) to store:
- GitHub App installations and repositories
- OAuth user tokens and information
- All data is persisted between server restarts
Required environment variables:
GITHUB_APP_ID: Your GitHub App IDGITHUB_APP_SLUG: Your GitHub App name/slug (for installation URLs)GITHUB_PRIVATE_KEY_PATH: Path to your private key fileGITHUB_CLIENT_ID: OAuth App client IDGITHUB_CLIENT_SECRET: OAuth App client secretCALLBACK_URL: OAuth callback URLAPP_CALLBACK_URL: GitHub App installation callback URLGITHUB_OAUTH_SCOPES: (optional) OAuth scopes to request. Defaults torepo,user:email.- To request read-only repository content, consider
repo:status repo:invite read:repoorrepodepending on needs. - Example for read-only content:
read:repoorrepo(repo includes write access; use with caution).
- To request read-only repository content, consider
Optional:
GITHUB_WEBHOOK_SECRET: For webhook verification (if using webhooks)PORT: Server port (default: 3000)
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
API documentation |
| GET | /health |
Health check |
| GET | /app/auth |
GitHub App authentication |
| GET | /app/callback |
GitHub App installation callback |
| POST | /app/refresh |
Refresh GitHub App data |
| GET | /app/installations |
List installations |
| GET | /app/repositories |
List repositories |
| GET | /auth/github |
OAuth authorization |
| GET | /auth/github/callback |
OAuth callback |
| GET | /auth/user/:userId |
Get user info |
| POST | /diff/app |
Calculate diff (GitHub App) |
| POST | /diff/oauth |
Calculate diff (OAuth) |
| POST | /webhook |
Webhook endpoint (optional) |
- Call
GET /app/authto get installation URL - User visits the installation URL and installs the app
- GitHub redirects to
/app/callbackwith installation details - Server stores installation and repository data
- Use installation_id for API calls that require GitHub App authentication
- Call
GET /auth/github(user is redirected to GitHub) - User authorizes the application
- GitHub redirects to
/auth/github/callback - Server exchanges code for access token and stores user data
- Use user_id for API calls that require OAuth authentication
The server includes comprehensive error handling for:
- Missing configuration
- Invalid authentication
- API rate limits
- Network errors
- Invalid parameters
All errors return JSON responses with appropriate HTTP status codes.