1
- # GitHub Webhook Integration Setup and Testing Guide
1
+ # Gitea Webhook Integration Setup and Testing Guide
2
2
3
3
## Overview
4
4
5
- The Topcoder Review API includes a secure GitHub webhook integration that receives webhook events from GitHub repositories, validates them using HMAC-SHA256 signature verification, and stores them in the database for audit and future processing.
5
+ The Topcoder Review API includes a secure Gitea webhook integration that receives webhook events from Gitea repositories, validates them using HMAC-SHA256 signature verification, and stores them in the database for audit and future processing.
6
6
7
7
## Table of Contents
8
8
9
9
1 . [ Quick Start] ( #quick-start )
10
10
2 . [ Environment Setup] ( #environment-setup )
11
- 3 . [ GitHub Repository Configuration] ( #github -repository-configuration )
11
+ 3 . [ Gitea Repository Configuration] ( #Gitea -repository-configuration )
12
12
4 . [ Local Development Setup] ( #local-development-setup )
13
13
5 . [ Testing the Integration] ( #testing-the-integration )
14
14
6 . [ API Endpoint Reference] ( #api-endpoint-reference )
@@ -23,7 +23,7 @@ For immediate setup, follow these steps:
23
23
24
24
1 . Generate a secure webhook secret
25
25
2 . Configure environment variables
26
- 3 . Set up GitHub webhook in repository settings
26
+ 3 . Set up Gitea webhook in repository settings
27
27
4 . Test with a sample event
28
28
29
29
## Environment Setup
@@ -34,22 +34,24 @@ Add the following environment variable to your application configuration:
34
34
35
35
``` bash
36
36
# .env file
37
- GITHUB_WEBHOOK_SECRET =your_generated_secret_here
37
+ GITEA_WEBHOOK_SECRET =your_generated_secret_here
38
38
```
39
39
40
40
### Generate Webhook Secret
41
41
42
42
** Using OpenSSL:**
43
+
43
44
``` bash
44
45
openssl rand -hex 32
45
46
```
46
47
47
48
** Example Output:**
49
+
48
50
```
49
51
a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456
50
52
```
51
53
52
- ⚠️ ** Important:** Store this secret securely and use the same value in both your application environment and GitHub webhook configuration.
54
+ ⚠️ ** Important:** Store this secret securely and use the same value in both your application environment and Gitea webhook configuration.
53
55
54
56
### Database Setup
55
57
@@ -59,11 +61,11 @@ The webhook integration requires the `gitWebhookLog` table. If not already creat
59
61
npx prisma migrate dev
60
62
```
61
63
62
- ## GitHub Repository Configuration
64
+ ## Gitea Repository Configuration
63
65
64
66
### Step 1: Access Repository Settings
65
67
66
- 1 . Navigate to your GitHub repository
68
+ 1 . Navigate to your Gitea repository
67
69
2 . Click on the ** Settings** tab (requires admin permissions)
68
70
3 . In the left sidebar, click ** Webhooks**
69
71
4 . Click ** Add webhook**
@@ -73,25 +75,30 @@ npx prisma migrate dev
73
75
#### Payload URL
74
76
75
77
** Production/Staging Environment:**
78
+
76
79
```
77
- https://your-api-domain.com/v6/review/webhooks/git
80
+ https://your-api-domain.com/v6/review/webhooks/gitea
78
81
```
79
82
80
83
** Development Environment:**
84
+
81
85
```
82
- https://your-dev-domain.com/webhooks/git
86
+ https://your-dev-domain.com/webhooks/gitea
83
87
```
84
88
85
89
Note: The ` /v6/review ` prefix is only added in production when ` NODE_ENV=production ` .
86
90
87
91
#### Content Type
92
+
88
93
- Select ` application/json `
89
94
90
95
#### Secret
96
+
91
97
- Enter the webhook secret you generated earlier
92
- - This must exactly match your ` GITHUB_WEBHOOK_SECRET ` environment variable
98
+ - This must exactly match your ` GITEA_WEBHOOK_SECRET ` environment variable
93
99
94
100
#### SSL Verification
101
+
95
102
- Keep ** Enable SSL verification** checked (recommended for production)
96
103
- For development with proper HTTPS setup, this should remain enabled
97
104
@@ -100,10 +107,12 @@ Note: The `/v6/review` prefix is only added in production when `NODE_ENV=product
100
107
Choose one of the following options:
101
108
102
109
** Option A: Send Everything (Recommended for Testing)**
103
- - Select "Send me everything" to receive all GitHub event types
110
+
111
+ - Select "Send me everything" to receive all Gitea event types
104
112
105
113
** Option B: Select Individual Events**
106
114
Common events for development workflows:
115
+
107
116
- ** Pushes** - Code pushes to repository
108
117
- ** Pull requests** - PR creation, updates, merges
109
118
- ** Issues** - Issue creation, updates, comments
@@ -116,18 +125,20 @@ Common events for development workflows:
116
125
117
126
1 . Ensure ** Active** checkbox is checked
118
127
2 . Click ** Add webhook**
119
- 3 . GitHub will automatically send a ` ping ` event to test the webhook
128
+ 3 . Gitea will automatically send a ` ping ` event to test the webhook
120
129
121
130
## Local Development Setup
122
131
123
- Since GitHub webhooks require a publicly accessible URL, local development requires exposing your local server to the internet.
132
+ Since Gitea webhooks require a publicly accessible URL, local development requires exposing your local server to the internet.
124
133
125
134
** Install ngrok:**
135
+
126
136
``` bash
127
137
npm install -g ngrok
128
138
```
129
139
130
140
** Setup process:**
141
+
131
142
``` bash
132
143
# 1. Start your local API server
133
144
pnpm run start:dev
@@ -138,16 +149,17 @@ ngrok http 3000
138
149
# 3. Copy the HTTPS URL from ngrok output
139
150
# Example: https://abc123.ngrok.io
140
151
141
- # 4. Use this URL in GitHub webhook settings
142
- # https://abc123.ngrok.io/webhooks/git
152
+ # 4. Use this URL in Gitea webhook settings
153
+ # https://abc123.ngrok.io/webhooks/gitea
143
154
```
155
+
144
156
## Testing the Integration
145
157
146
158
### Manual Testing
147
159
148
160
#### 1. Verify Initial Setup
149
161
150
- After creating the webhook, GitHub automatically sends a ` ping ` event:
162
+ After creating the webhook, Gitea automatically sends a ` ping ` event:
151
163
152
164
1 . Go to your repository's webhook settings
153
165
2 . Click on your webhook
@@ -157,6 +169,7 @@ After creating the webhook, GitHub automatically sends a `ping` event:
157
169
#### 2. Trigger Test Events
158
170
159
171
** Create a Push Event:**
172
+
160
173
``` bash
161
174
# Make a small change
162
175
echo " webhook test" >> test-webhook.txt
@@ -166,16 +179,18 @@ git push origin main
166
179
```
167
180
168
181
** Create an Issue:**
169
- 1 . Go to your repository on GitHub
182
+
183
+ 1 . Go to your repository on Gitea
170
184
2 . Click ** Issues** tab
171
185
3 . Click ** New issue**
172
186
4 . Create a test issue
173
187
174
188
** Create a Pull Request:**
189
+
175
190
1 . Create a new branch: ` git checkout -b test-webhook `
176
191
2 . Make changes and commit
177
192
3 . Push branch: ` git push origin test-webhook `
178
- 4 . Open pull request on GitHub
193
+ 4 . Open pull request on Gitea
179
194
180
195
### Testing with curl
181
196
@@ -185,7 +200,7 @@ You can test the webhook endpoint directly using curl with proper signature gene
185
200
#! /bin/bash
186
201
187
202
# Configuration
188
- WEBHOOK_URL=" http://localhost:3000/webhooks/git " # Adjust for your environment
203
+ WEBHOOK_URL=" http://localhost:3000/webhooks/gitea " # Adjust for your environment
189
204
WEBHOOK_SECRET=" your_webhook_secret_here"
190
205
PAYLOAD=' {"test": "data", "repository": {"name": "test-repo"}}'
191
206
DELIVERY_ID=" test-delivery-$( date +%s) "
@@ -197,8 +212,8 @@ SIGNATURE="sha256=$(echo -n "$PAYLOAD" | openssl dgst -sha256 -hmac "$WEBHOOK_SE
197
212
# Send test webhook
198
213
curl -X POST " $WEBHOOK_URL " \
199
214
-H " Content-Type: application/json" \
200
- -H " X-GitHub -Event: $EVENT_TYPE " \
201
- -H " X-GitHub -Delivery: $DELIVERY_ID " \
215
+ -H " X-Gitea -Event: $EVENT_TYPE " \
216
+ -H " X-Gitea -Delivery: $DELIVERY_ID " \
202
217
-H " X-Hub-Signature-256: $SIGNATURE " \
203
218
-d " $PAYLOAD "
204
219
```
@@ -207,24 +222,28 @@ curl -X POST "$WEBHOOK_URL" \
207
222
208
223
### Webhook Endpoint
209
224
210
- ** URL:** ` POST /webhooks/git ` (development) or ` POST /v6/review/webhooks/git ` (production)
225
+ ** URL:** ` POST /webhooks/gitea ` (development) or ` POST /v6/review/webhooks/gitea ` (production)
211
226
212
227
** Required Headers:**
228
+
213
229
- ` Content-Type: application/json `
214
- - ` X-GitHub -Event: {event_type} ` - GitHub event type (push, pull_request, etc.)
215
- - ` X-GitHub -Delivery: {delivery_id} ` - Unique delivery identifier from GitHub
230
+ - ` X-Gitea -Event: {event_type} ` - Gitea event type (push, pull_request, etc.)
231
+ - ` X-Gitea -Delivery: {delivery_id} ` - Unique delivery identifier from Gitea
216
232
- ` X-Hub-Signature-256: sha256={signature} ` - HMAC-SHA256 signature for verification
217
233
218
234
** Request Body:**
219
- - GitHub webhook payload (varies by event type)
235
+
236
+ - Gitea webhook payload (varies by event type)
220
237
221
238
** Response Codes:**
239
+
222
240
- ` 200 OK ` - Webhook processed successfully
223
241
- ` 400 Bad Request ` - Missing required headers or invalid payload
224
242
- ` 403 Forbidden ` - Invalid signature verification
225
243
- ` 500 Internal Server Error ` - Processing error or configuration issue
226
244
227
245
** Success Response:**
246
+
228
247
``` json
229
248
{
230
249
"success" : true ,
@@ -233,13 +252,14 @@ curl -X POST "$WEBHOOK_URL" \
233
252
```
234
253
235
254
** Error Response:**
255
+
236
256
``` json
237
257
{
238
258
"statusCode" : 403 ,
239
259
"message" : " Invalid signature" ,
240
260
"error" : " Forbidden" ,
241
261
"timestamp" : " 2024-01-01T00:00:00.000Z" ,
242
- "path" : " /webhooks/git "
262
+ "path" : " /webhooks/gitea "
243
263
}
244
264
```
245
265
@@ -254,7 +274,7 @@ CREATE TABLE "gitWebhookLog" (
254
274
" event" TEXT NOT NULL ,
255
275
" eventPayload" JSONB NOT NULL ,
256
276
" createdAt" TIMESTAMP (3 ) NOT NULL DEFAULT CURRENT_TIMESTAMP ,
257
-
277
+
258
278
CONSTRAINT " gitWebhookLog_pkey" PRIMARY KEY (" id" )
259
279
);
260
280
@@ -267,43 +287,46 @@ CREATE INDEX "gitWebhookLog_createdAt_idx" ON "gitWebhookLog"("createdAt");
267
287
### Query Examples
268
288
269
289
** View recent webhook events:**
290
+
270
291
``` sql
271
- SELECT
292
+ SELECT
272
293
id,
273
294
" eventId" ,
274
295
event,
275
296
" createdAt"
276
- FROM " gitWebhookLog"
277
- ORDER BY " createdAt" DESC
297
+ FROM " gitWebhookLog"
298
+ ORDER BY " createdAt" DESC
278
299
LIMIT 10 ;
279
300
```
280
301
281
302
** Filter by event type:**
303
+
282
304
``` sql
283
- SELECT * FROM " gitWebhookLog"
284
- WHERE event = ' push'
305
+ SELECT * FROM " gitWebhookLog"
306
+ WHERE event = ' push'
285
307
ORDER BY " createdAt" DESC ;
286
308
```
287
309
288
310
** View specific webhook payload:**
311
+
289
312
``` sql
290
- SELECT
313
+ SELECT
291
314
event,
292
315
" eventPayload"
293
- FROM " gitWebhookLog"
316
+ FROM " gitWebhookLog"
294
317
WHERE " eventId" = ' your-delivery-id' ;
295
318
```
296
319
297
320
## Security Considerations
298
321
299
322
### Signature Verification
300
323
301
- The webhook implementation uses GitHub 's recommended security practices:
324
+ The webhook implementation uses Gitea 's recommended security practices:
302
325
303
326
1 . ** HMAC-SHA256 Signature:** All incoming webhooks are verified using HMAC-SHA256
304
327
2 . ** Timing-Safe Comparison:** Uses ` crypto.timingSafeEqual() ` to prevent timing attacks
305
328
3 . ** Secret Protection:** Webhook secrets are stored as environment variables
306
- 4 . ** Header Validation:** Validates all required GitHub headers
329
+ 4 . ** Header Validation:** Validates all required Gitea headers
307
330
308
331
### Best Practices
309
332
@@ -315,7 +338,7 @@ The webhook implementation uses GitHub's recommended security practices:
315
338
316
339
### Environment Security
317
340
318
- - Store ` GITHUB_WEBHOOK_SECRET ` securely using your deployment platform's secret management
341
+ - Store ` GITEA_WEBHOOK_SECRET ` securely using your deployment platform's secret management
319
342
- Never commit secrets to version control
320
343
- Use different secrets for different environments
321
344
- Implement proper secret rotation procedures
@@ -326,25 +349,11 @@ Key log messages to monitor:
326
349
327
350
```
328
351
# Successful webhook processing
329
- [WebhookController] Successfully processed GitHub webhook
352
+ [WebhookController] Successfully processed Gitea webhook
330
353
331
354
# Signature validation failures
332
- [GitHubSignatureGuard ] Invalid webhook signature for delivery
355
+ [GiteaSignatureGuard ] Invalid webhook signature for delivery
333
356
334
357
# Configuration errors
335
- [GitHubSignatureGuard] GITHUB_WEBHOOK_SECRET environment variable is not configured
336
- ```
337
-
338
- Example
339
-
340
- ```
341
- [2025-08-02T01:06:48.312Z] [LOG] [Bootstrap] Server started on port 3000
342
- [2025-08-02T01:07:15.700Z] [LOG] [HttpRequest] {"type":"request","method":"POST","url":"/webhooks/git","ip":"::1","userAgent":"GitHub-Hookshot/4f8bd7a"}
343
- [2025-08-02T01:07:15.739Z] [LOG] [GitHubSignatureGuard] Valid webhook signature verified for delivery 0722d0bc-6f3d-11f0-8a2d-6cc18966c098, event push
344
- [2025-08-02T01:07:15.740Z] [LOG] [WebhookController] {"message":"Received GitHub webhook","delivery":"0722d0bc-6f3d-11f0-8a2d-6cc18966c098","event":"push","timestamp":"2025-08-02T01:07:15.740Z"}
345
- [2025-08-02T01:07:15.740Z] [LOG] [WebhookService] {"message":"Processing GitHub webhook event","eventId":"0722d0bc-6f3d-11f0-8a2d-6cc18966c098","event":"push","timestamp":"2025-08-02T01:07:15.740Z"}
346
- [2025-08-02T01:07:15.804Z] [LOG] [WebhookService] {"message":"Successfully stored webhook event","eventId":"0722d0bc-6f3d-11f0-8a2d-6cc18966c098","event":"push","storedId":"9aHvEgDYPCYYnU","createdAt":"2025-08-02T01:07:15.747Z"}
347
- [2025-08-02T01:07:15.804Z] [LOG] [WebhookService] {"message":"Event-specific processing placeholder","event":"push","payloadSize":7979}
348
- [2025-08-02T01:07:15.804Z] [LOG] [WebhookController] {"message":"Successfully processed GitHub webhook","delivery":"0722d0bc-6f3d-11f0-8a2d-6cc18966c098","event":"push","success":true}
349
- [2025-08-02T01:07:15.804Z] [LOG] [HttpRequest] {"type":"response","statusCode":200,"method":"POST","url":"/webhooks/git","responseTime":"104ms"}
358
+ [GiteaSignatureGuard] Gitea_WEBHOOK_SECRET environment variable is not configured
350
359
```
0 commit comments