fix GitHub event handling for tag deployments.

This commit is contained in:
Theo D
2025-04-21 02:25:41 +02:00
parent 8c36e48fe7
commit 459c94929a
2 changed files with 8 additions and 9 deletions

View File

@@ -62,12 +62,11 @@ export default async function handler(
if ( if (
req.headers["x-github-event"] !== "push" && req.headers["x-github-event"] !== "push" &&
req.headers["x-github-event"] !== "pull_request" && req.headers["x-github-event"] !== "pull_request"
req.headers["x-github-event"] !== "create"
) { ) {
res res
.status(400) .status(400)
.json({ message: "We only accept push, pull_request, or create events" }); .json({ message: "We only accept push events or pull_request events" });
return; return;
} }
@@ -92,17 +91,17 @@ export default async function handler(
// Handle tag creation event // Handle tag creation event
if ( if (
req.headers["x-github-event"] === "create" && req.headers["x-github-event"] === "push" &&
githubBody?.ref_type === "tag" githubBody?.ref?.startsWith("refs/tags/")
) { ) {
try { try {
const tagName = githubBody?.ref; const tagName = githubBody?.ref.replace("refs/tags/", "");
const repository = githubBody?.repository?.name; const repository = githubBody?.repository?.name;
const owner = const owner =
githubBody?.repository?.owner?.name || githubBody?.repository?.owner?.name ||
githubBody?.repository?.owner?.login; githubBody?.repository?.owner?.login;
const deploymentTitle = `Tag created: ${tagName}`; const deploymentTitle = `Tag created: ${tagName}`;
const deploymentHash = githubBody?.master_branch || ""; const deploymentHash = extractHash(req.headers, githubBody);
// Find applications configured to deploy on tag // Find applications configured to deploy on tag
const apps = await db.query.applications.findMany({ const apps = await db.query.applications.findMany({
@@ -120,7 +119,7 @@ export default async function handler(
const jobData: DeploymentJob = { const jobData: DeploymentJob = {
applicationId: app.applicationId as string, applicationId: app.applicationId as string,
titleLog: deploymentTitle, titleLog: deploymentTitle,
descriptionLog: `Tag: ${tagName}`, descriptionLog: `Hash: ${deploymentHash}`,
type: "deploy", type: "deploy",
applicationType: "application", applicationType: "application",
server: !!app.serverId, server: !!app.serverId,
@@ -159,7 +158,7 @@ export default async function handler(
titleLog: deploymentTitle, titleLog: deploymentTitle,
type: "deploy", type: "deploy",
applicationType: "compose", applicationType: "compose",
descriptionLog: `Tag: ${tagName}`, descriptionLog: `Hash: ${deploymentHash}`,
server: !!composeApp.serverId, server: !!composeApp.serverId,
}; };