You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
870 B
TypeScript
30 lines
870 B
TypeScript
import type { APIRoute } from 'astro'
|
|
|
|
import { loadConfig } from '@/config'
|
|
|
|
import { debug } from '@/logger'
|
|
import { normalizeURL } from '@/lib/utils'
|
|
|
|
import { enqueueJob } from '@/jobs'
|
|
import { createDeployJob } from '@/deploys'
|
|
|
|
export const POST: APIRoute = async ({ request }) => {
|
|
const body = await request.json()
|
|
const { html_url: htmlUrl, clone_url: cloneUrl, ssh_url: sshUrl } = body.repository
|
|
|
|
const URLS = [htmlUrl, cloneUrl, sshUrl]
|
|
|
|
const { deploys } = await loadConfig()
|
|
|
|
for (const deploy of deploys) {
|
|
if (deploy.type !== 'docker') {
|
|
if (URLS.includes(normalizeURL(deploy.url))) {
|
|
debug(`[Webhook] Triggering deploy for "${deploy.url}"`)
|
|
enqueueJob(createDeployJob(deploy, { event: 'webhook', url: deploy.url }))
|
|
}
|
|
}
|
|
}
|
|
|
|
return new Response('ok')
|
|
}
|