import type { APIRoute } from "astro"; import { readFile } from "node:fs/promises"; import { execFile } from "node:child_process"; import { join } from "node:path"; const ROOT = process.env.REPO_ROOT!; export const POST: APIRoute = async () => { try { const envFile = await readFile(join(ROOT, "palaces/manglasabang/secretariat/keychain/linear.env"), "utf-8"); const keyMatch = envFile.match(/LINEAR_API_KEY='([^']+)'/); if (!keyMatch) throw new Error("LINEAR_API_KEY not found in keychain"); await new Promise((resolve, reject) => { execFile("/bin/sh", ["-c", "/opt/homebrew/bin/pnpm tsx linear/sync.ts"], { env: { ...process.env, PATH: "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", LINEAR_API_KEY: keyMatch[1] }, cwd: join(ROOT, "code/palaceplatform/channels"), timeout: 30000, }, (err) => (err ? reject(err) : resolve())); }); return new Response(JSON.stringify({ ok: true }), { headers: { "Content-Type": "application/json" }, }); } catch (err: any) { return new Response(JSON.stringify({ ok: false, error: err.message }), { status: 500, headers: { "Content-Type": "application/json" }, }); } };