Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor (options: Options) {
options.webhookPath = options.webhookPath || '/'
options.secret = options.secret || 'development'
this.options = options
this.logger = logger
this.apps = []
this.webhook = new Webhooks({
path: options.webhookPath,
secret: options.secret
})
this.githubToken = options.githubToken
this.Octokit = options.Octokit || ProbotOctokit
if (this.options.id) {
if (process.env.GHE_HOST && /^https?:\/\//.test(process.env.GHE_HOST)) {
throw new Error('Your \`GHE_HOST\` environment variable should not begin with https:// or http://')
}
this.app = new OctokitApp({
baseUrl: process.env.GHE_HOST && `https://${process.env.GHE_HOST}/api/v3`,
id: options.id as number,
privateKey: options.cert as string
})
}
export default async function handleWebhook(
req: CloudFunctionsRequest,
res: Response,
) {
const secret = await keyManager.getWebhookSecret();
const webhooks = new WebhooksApi({
secret,
});
if (!webhooks.verify(req.rawBody.toString(), req.get('X-Hub-Signature'))) {
console.error('Invalid signature.');
res.status(HttpStatus.BAD_REQUEST).end();
return;
}
const event = req.body;
const eventType = req.get('X-GitHub-Event');
switch (eventType) {
case 'pull_request':
await handlePullRequest(event as PullRequest);
break;
default:
export async function handleWebhook(req: any, res: any) {
if (
!verify(
await keyManager.getWebhookSecret(),
req.rawBody.toString(),
req.get('X-Hub-Signature'),
)
) {
console.error('Invalid signature.');
res.status(400).end();
return;
}
const event = req.body;
const eventType = req.get('X-GitHub-Event');
switch (eventType) {
case 'pull_request':
await handlePullRequest(event);
break;
import WebhooksApi from '@octokit/webhooks'
import { handleGitHubEvents } from 'modules/github'
const webhooks = new WebhooksApi({
secret: process.env.GITHUB_WEBHOOK_SECRET,
path: '/event-handler',
})
webhooks.on('*', handleGitHubEvents)
export default webhooks.middleware