summaryrefslogtreecommitdiff
path: root/hooks/mod.ts
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2025-05-12 09:40:12 -0700
committerElizabeth <me@liz.coffee>2025-05-26 14:15:42 -0700
commitd51c9d74857aca3c2f172609297266968bc7f809 (patch)
tree64327f9cc4219729aa11af32d7d4c70cddfc2292 /hooks/mod.ts
parent30729a0cf707d9022bae0a7baaba77379dc31fd5 (diff)
downloadci-d51c9d74857aca3c2f172609297266968bc7f809.tar.gz
ci-d51c9d74857aca3c2f172609297266968bc7f809.zip
The big refactor TM
Diffstat (limited to 'hooks/mod.ts')
-rw-r--r--[-rwxr-xr-x]hooks/mod.ts80
1 files changed, 2 insertions, 78 deletions
diff --git a/hooks/mod.ts b/hooks/mod.ts
index f858ad0..cc15112 100755..100644
--- a/hooks/mod.ts
+++ b/hooks/mod.ts
@@ -1,78 +1,2 @@
-#!/usr/bin/env -S deno run --allow-env --allow-net --allow-run
-
-import {
- getRequiredEnv,
- getStdout,
- loggerWithPrefix,
- validateIdentifier,
-} from "@liz-ci/utils";
-
-const getRequestLogger = (req: Request) => {
- const url = new URL(req.url);
- const traceId = crypto.randomUUID();
- const getPrefix = () =>
- `[${
- new Date().toISOString()
- }] RequestTrace=[${traceId}] @ [${url.pathname}] -X [${req.method}] |`;
- return loggerWithPrefix(getPrefix);
-};
-
-const addr = { port: 9000, hostname: "0.0.0.0" };
-Deno.serve(addr, async (req) => {
- const logger = getRequestLogger(req);
- logger.log("start");
-
- try {
- const { pathname } = new URL(req.url);
- if (pathname === "/health") {
- try {
- getRequiredEnv("LAMINAR_HOST");
- await getStdout(["laminarc", "show-jobs"]);
- return new Response("think im healthy!! lets get to work.\n", {
- status: 200,
- });
- } catch (e) {
- logger.error(e);
- return new Response("i need to eat more vegetables -.-\n", {
- status: 500,
- });
- }
- }
-
- if (req.method !== "POST") {
- return new Response("invalid method", {
- status: 405,
- });
- }
-
- if (pathname === "/checkout_ci") {
- const { remote, rev, refname } = await req.json();
- if (![remote, rev, refname].every(validateIdentifier)) {
- logger.log("invalid reqwest");
- return new Response("invalid reqwest >:D\n", {
- status: 400,
- });
- }
-
- const laminar = await getStdout([
- "laminarc",
- "queue",
- "checkout_ci",
- `remote="${remote}"`,
- `rev="${rev}"`,
- `refname="${refname}"`,
- ]);
- logger.log(`successful queue :D`, laminar);
- return new Response(laminar + "\n", {
- status: 200,
- });
- }
-
- return new Response("idk what that is bro :((\n", { status: 404 });
- } catch (e) {
- logger.error("uncaught exception", e);
- return new Response("womp womp D:\n", { status: 500 });
- } finally {
- logger.log("finish");
- }
-});
+export * from "./server/mod.ts";
+export * from "./main.ts";