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.
36 lines
1003 B
TypeScript
36 lines
1003 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-image') {
|
|
if (URLS.includes(normalizeURL(deploy.url))) {
|
|
debug(`[Webhook] Triggering deploy for "${deploy.url}"`)
|
|
|
|
const [jobBase, deployFn] = createDeployJob(deploy, {
|
|
event: 'webhook',
|
|
url: deploy.url,
|
|
})
|
|
|
|
await enqueueJob(jobBase, deployFn)
|
|
}
|
|
}
|
|
}
|
|
|
|
return new Response('ok')
|
|
}
|