summaryrefslogtreecommitdiff
path: root/hooks/mod.ts
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2025-05-10 16:57:03 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2025-05-10 16:57:03 -0700
commitfa8f3f9465e87d499f7d6428323f496a884b7818 (patch)
treeab477dfa52ef30282029c4f136bf605cb24d67a9 /hooks/mod.ts
downloadci-fa8f3f9465e87d499f7d6428323f496a884b7818.tar.gz
ci-fa8f3f9465e87d499f7d6428323f496a884b7818.zip
initial commit
Diffstat (limited to 'hooks/mod.ts')
-rw-r--r--hooks/mod.ts57
1 files changed, 57 insertions, 0 deletions
diff --git a/hooks/mod.ts b/hooks/mod.ts
new file mode 100644
index 0000000..f432b72
--- /dev/null
+++ b/hooks/mod.ts
@@ -0,0 +1,57 @@
+#!/usr/bin/env -S deno run --allow-env --allow-net
+
+import { getStdout, validateIdentifier } from "@liz-ci/utils";
+
+const addr = { port: 9000, hostname: "0.0.0.0" };
+
+Deno.serve(addr, async (req) => {
+ const { pathname } = new URL(req.url);
+ if (pathname === "/health") {
+ try {
+ await getStdout(["laminarc", "show-jobs"]);
+ return new Response("think im healthy. lets get to work.", {
+ status: 200,
+ });
+ } catch (e) {
+ console.error(e);
+ return new Response("i need to eat more vegetables -.-", { 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)) {
+ return new Response("invalid request", {
+ status: 400,
+ });
+ }
+
+ try {
+ const laminar = await getStdout([
+ "laminarc",
+ "queue",
+ "checkout_ci",
+ `remote="${remote}"`,
+ `rev="${rev}"`,
+ `refname="${refname}"`,
+ ]);
+ console.log(`successful ci queue :D\n` + laminar);
+ return new Response(laminar, {
+ status: 200,
+ });
+ } catch (e) {
+ console.error(e);
+ return new Response("womp womp D:", {
+ status: 500,
+ });
+ }
+ }
+
+ return new Response("ahhhh idkkkk", { status: 404 });
+});