|
1 |
| -# gh-service: GitHub Repository Event Monitor |
| 1 | +# GitHub Webhook Service Deployment |
2 | 2 |
|
3 |
| -Real-time monitoring system for GitHub repository events across multiple repositories. |
| 3 | +This directory contains the GitHub webhook service and deployment configuration for Google Cloud Run. |
4 | 4 |
|
5 |
| -## Features |
| 5 | +## Overview |
6 | 6 |
|
7 |
| -- **Real-time notifications** for issues, PRs, comments, and label changes |
8 |
| -- **Dual mode support**: Webhooks (real-time) or Polling (30s interval) |
9 |
| -- **Multi-repository monitoring** across 4 Comfy-Org repositories |
10 |
| -- **Secure webhook verification** with HMAC signatures |
11 |
| -- **Automatic webhook setup** with graceful fallback to polling |
| 7 | +The webhook service (`index.tsx`) monitors GitHub repositories for events like issues, pull requests, and comments. It can operate in two modes: |
12 | 8 |
|
13 |
| -## Quick Start |
| 9 | +- **Webhook mode**: Real-time event handling via GitHub webhooks |
| 10 | +- **Polling mode**: Fallback polling when webhooks can't be configured |
14 | 11 |
|
15 |
| -### Polling Mode (Default) |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +1. **Google Cloud CLI**: Install and authenticate with `gcloud auth login` |
| 15 | +2. **Docker**: Required for building container images |
| 16 | +3. **Project Setup**: Enable billing on your Google Cloud project |
| 17 | +4. **GitHub Token**: Personal Access Token with repo permissions |
| 18 | +5. **Webhook Secret**: Secret for securing webhook payloads |
| 19 | + |
| 20 | +## Environment Variables |
| 21 | + |
| 22 | +The service requires these environment variables: |
| 23 | + |
| 24 | +### Required |
| 25 | + |
| 26 | +- `GITHUB_TOKEN`: GitHub Personal Access Token |
| 27 | +- `GITHUB_WEBHOOK_SECRET`: Secret for webhook signature validation |
| 28 | +- `PORT`: Server port (defaults to 8080) |
| 29 | + |
| 30 | +### Optional |
| 31 | + |
| 32 | +- `GITHUB_WEBHOOK_BASEURL`: Base URL for webhook endpoints |
| 33 | +- `GITHUB_WEBHOOK_PORT`: Alternative port setting |
| 34 | + |
| 35 | +## Deployment |
| 36 | + |
| 37 | +### Quick Deploy |
16 | 38 |
|
17 | 39 | ```bash
|
18 |
| -bun run run/gh-service.tsx |
| 40 | +# Set environment variables |
| 41 | +export GOOGLE_CLOUD_PROJECT="your-project-id" |
| 42 | +export GITHUB_TOKEN="ghp_your_token_here" |
| 43 | +export GITHUB_WEBHOOK_SECRET="your_webhook_secret" |
| 44 | + |
| 45 | +# Deploy |
| 46 | +cd run |
| 47 | +./deploy.sh |
19 | 48 | ```
|
20 | 49 |
|
21 |
| -### Webhook Mode (Real-time) |
| 50 | +### Manual Deploy Steps |
| 51 | + |
| 52 | +1. **Enable APIs**: |
| 53 | + |
| 54 | + ```bash |
| 55 | + gcloud services enable cloudbuild.googleapis.com run.googleapis.com artifactregistry.googleapis.com secretmanager.googleapis.com |
| 56 | + ``` |
| 57 | + |
| 58 | +2. **Create Artifact Registry**: |
| 59 | + |
| 60 | + ```bash |
| 61 | + gcloud artifacts repositories create github-webhook-service \ |
| 62 | + --repository-format=docker \ |
| 63 | + --location=us-central1 |
| 64 | + ``` |
| 65 | + |
| 66 | +3. **Create Secrets**: |
| 67 | + |
| 68 | + ```bash |
| 69 | + echo "$GITHUB_TOKEN" | gcloud secrets create github-token --data-file=- |
| 70 | + echo "$GITHUB_WEBHOOK_SECRET" | gcloud secrets create github-webhook-secret --data-file=- |
| 71 | + ``` |
| 72 | + |
| 73 | +4. **Build and Deploy**: |
| 74 | + ```bash |
| 75 | + gcloud builds submit . --config=cloudbuild.yaml |
| 76 | + ``` |
| 77 | + |
| 78 | +## Files |
| 79 | + |
| 80 | +- `index.tsx` - Main webhook service application |
| 81 | +- `Dockerfile` - Container build configuration |
| 82 | +- `cloudbuild.yaml` - Cloud Build deployment configuration |
| 83 | +- `deploy.sh` - Automated deployment script |
| 84 | +- `README.md` - This documentation |
| 85 | + |
| 86 | +## Service Endpoints |
| 87 | + |
| 88 | +- `/` - Root endpoint with basic info |
| 89 | +- `/api/github/webhook` - GitHub webhook endpoint |
| 90 | +- `/health` - Health check endpoint |
| 91 | + |
| 92 | +## GitHub Webhook Configuration |
| 93 | + |
| 94 | +After deployment, configure your GitHub repositories: |
| 95 | + |
| 96 | +1. Go to Repository Settings → Webhooks |
| 97 | +2. Add webhook with URL: `https://your-service-url/api/github/webhook` |
| 98 | +3. Set content type to `application/json` |
| 99 | +4. Enter your webhook secret |
| 100 | +5. Select events: Issues, Pull requests, Issue comments, Pull request reviews, Labels |
| 101 | + |
| 102 | +## Local Development |
22 | 103 |
|
23 | 104 | ```bash
|
24 |
| -export USE_WEBHOOKS=true |
25 |
| -export GITHUB_WEBHOOK_SECRET=your-webhook-secret |
26 |
| -export WEBHOOK_BASE_URL=https://your-public-domain.com |
27 |
| -bun run run/gh-service.tsx |
| 105 | +# Install dependencies |
| 106 | +bun install |
| 107 | + |
| 108 | +# Set environment variables |
| 109 | +export GITHUB_TOKEN="your_token" |
| 110 | +export GITHUB_WEBHOOK_SECRET="your_secret" |
| 111 | +export PORT=3000 |
| 112 | + |
| 113 | +# Run locally |
| 114 | +bun run index.tsx |
28 | 115 | ```
|
29 | 116 |
|
30 | 117 | ## Getting Your Webhook Secret
|
|
0 commit comments