mirror of
https://github.com/snowball-tools/snowballtools-base.git
synced 2025-01-26 07:30:34 +00:00
Nabarun Gogoi
c4ba59d97e
* Create repo webhook and express handler for webhook * Create deployments from commits in GitHub * Update isCurrent in previous production deployment * Create script for setting authority * Update README for initialize registry script * Handle review changes * Use correct repo URL in record data * Handle github unique webhook error * Handle async execution of publishing records * Update readme with ngrok setup * Review changes * Add logs for GitHub webhooks --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
27 lines
936 B
TypeScript
27 lines
936 B
TypeScript
import { Router } from 'express';
|
|
import debug from 'debug';
|
|
|
|
import { Service } from '../service';
|
|
|
|
const log = debug('snowball:routes-github');
|
|
const router = Router();
|
|
|
|
/* POST GitHub webhook handler */
|
|
// https://docs.github.com/en/webhooks/using-webhooks/handling-webhook-deliveries#javascript-example
|
|
router.post('/webhook', async (req, res) => {
|
|
// Server should respond with a 2XX response within 10 seconds of receiving a webhook delivery
|
|
// If server takes longer than that to respond, then GitHub terminates the connection and considers the delivery a failure
|
|
res.status(202).send('Accepted');
|
|
|
|
const service = req.app.get('service') as Service;
|
|
const githubEvent = req.headers['x-github-event'];
|
|
log(`Received GitHub webhook for event ${githubEvent}`);
|
|
|
|
if (githubEvent === 'push') {
|
|
// Create deployments using push event data
|
|
await service.handleGitHubPush(req.body);
|
|
}
|
|
});
|
|
|
|
export default router;
|