Blame · Line-by-line history
post-receive.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| fc1817a | 1 | /** |
| 2 | * Post-receive hook logic. | |
| 3 | * Called after a successful git push to trigger GateTest scans | |
| 4 | * and Crontech deploys. | |
| 5 | */ | |
| 6 | ||
| 7 | import { config } from "../lib/config"; | |
| e883329 | 8 | import { runGateTestScan } from "../lib/gate"; |
| fc1817a | 9 | |
| 10 | interface PushRef { | |
| 11 | oldSha: string; | |
| 12 | newSha: string; | |
| 13 | refName: string; | |
| 14 | } | |
| 15 | ||
| 16 | export async function onPostReceive( | |
| 17 | owner: string, | |
| 18 | repo: string, | |
| 19 | refs: PushRef[] | |
| 20 | ): Promise<void> { | |
| 21 | const promises: Promise<void>[] = []; | |
| 22 | ||
| e883329 | 23 | // GateTest scan on every push (non-blocking, results stored for merge gating) |
| 24 | for (const ref of refs) { | |
| 25 | if (!ref.newSha.startsWith("0000")) { | |
| 26 | promises.push( | |
| 27 | runGateTestScan(owner, repo, ref.refName, ref.newSha) | |
| 28 | .then((result) => { | |
| 29 | console.log( | |
| 30 | `[gatetest] ${owner}/${repo} ${ref.refName}: ${result.passed ? "PASSED" : "FAILED"} — ${result.details}` | |
| 31 | ); | |
| 32 | }) | |
| 33 | .catch((err) => { | |
| 34 | console.error(`[gatetest] scan error for ${owner}/${repo}:`, err); | |
| 35 | }) | |
| 36 | ); | |
| 37 | } | |
| 38 | } | |
| fc1817a | 39 | |
| e883329 | 40 | // Crontech deploy on push to main (only if GateTest passes) |
| fc1817a | 41 | const mainPush = refs.find( |
| 42 | (r) => r.refName === "refs/heads/main" && !r.newSha.startsWith("0000") | |
| 43 | ); | |
| 44 | if (mainPush) { | |
| 45 | promises.push(triggerCrontechDeploy(owner, repo, mainPush.newSha)); | |
| 46 | } | |
| 47 | ||
| 48 | await Promise.allSettled(promises); | |
| 49 | } | |
| 50 | ||
| 51 | async function triggerCrontechDeploy( | |
| 52 | owner: string, | |
| 53 | repo: string, | |
| 54 | sha: string | |
| 55 | ): Promise<void> { | |
| 56 | try { | |
| 57 | const response = await fetch(config.crontechDeployUrl, { | |
| 58 | method: "POST", | |
| 59 | headers: { "Content-Type": "application/json" }, | |
| 60 | body: JSON.stringify({ | |
| 61 | repository: `${owner}/${repo}`, | |
| 62 | sha, | |
| 63 | branch: "main", | |
| 64 | source: "gluecron", | |
| 65 | }), | |
| 66 | }); | |
| 67 | console.log( | |
| 68 | `[crontech] deploy triggered for ${owner}/${repo}@${sha.slice(0, 7)}: ${response.status}` | |
| 69 | ); | |
| 70 | } catch (err) { | |
| 71 | console.error(`[crontech] failed to trigger deploy:`, err); | |
| 72 | } | |
| 73 | } |