summaryrefslogtreecommitdiff
path: root/server/ci.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2025-06-20 14:53:38 -0700
committerElizabeth Hunt <me@liz.coffee>2025-06-20 14:53:38 -0700
commitd4791f3d357634daf506fb8f91cc5332a794c421 (patch)
tree1bb01d2d4d8fa74d83bb6f99f2c8aa4146ca2d11 /server/ci.ts
parentd7e8d31c94cd713a2f4cf799e20e993acc69e361 (diff)
downloadci-d4791f3d357634daf506fb8f91cc5332a794c421.tar.gz
ci-d4791f3d357634daf506fb8f91cc5332a794c421.zip
Move to nodejs
Diffstat (limited to 'server/ci.ts')
-rw-r--r--server/ci.ts89
1 files changed, 40 insertions, 49 deletions
diff --git a/server/ci.ts b/server/ci.ts
index f8d4a17..f57c426 100644
--- a/server/ci.ts
+++ b/server/ci.ts
@@ -1,56 +1,47 @@
import {
- FourOhFourActivityImpl,
- getRequiredEnv,
- HealthCheckActivityImpl,
- type HealthChecker,
- type IFourOhFourActivity,
- type IHealthCheckActivity,
- type ITraceable,
- PenguenoRequest,
- type ServerTrace,
- TraceUtil,
-} from "@emprespresso/pengueno";
-import type { Job } from "@emprespresso/ci_model";
-import {
- healthCheck as _healthCheck,
- type IJobHookActivity,
- type IJobQueuer,
- JobHookActivityImpl,
- LaminarJobQueuer,
-} from "@emprespresso/ci_server";
+ FourOhFourActivityImpl,
+ getRequiredEnv,
+ HealthCheckActivityImpl,
+ type HealthChecker,
+ type IFourOhFourActivity,
+ type IHealthCheckActivity,
+ type ITraceable,
+ PenguenoRequest,
+ type ServerTrace,
+ TraceUtil,
+} from '@emprespresso/pengueno';
+import type { Job } from '@emprespresso/ci_model';
+import { type IJobHookActivity, type IJobQueuer, JobHookActivityImpl, LaminarJobQueuer } from './job';
+import { healthCheck as _healthCheck } from '.';
+
+export const DEFAULT_CI_SERVER = 'https://ci.liz.coffee';
export class CiHookServer {
- constructor(
- healthCheck: HealthChecker = _healthCheck,
- jobQueuer: IJobQueuer<ITraceable<Job, ServerTrace>> = new LaminarJobQueuer(
- getRequiredEnv("LAMINAR_URL").fold(({ isLeft, value }) =>
- isLeft ? "https://ci.liz.coffee" : value,
- ),
- ),
- private readonly healthCheckActivity: IHealthCheckActivity = new HealthCheckActivityImpl(
- healthCheck,
- ),
- private readonly jobHookActivity: IJobHookActivity = new JobHookActivityImpl(
- jobQueuer,
- ),
- private readonly fourOhFourActivity: IFourOhFourActivity = new FourOhFourActivityImpl(),
- ) {}
+ constructor(
+ healthCheck: HealthChecker = _healthCheck,
+ jobQueuer: IJobQueuer<ITraceable<Job, ServerTrace>> = new LaminarJobQueuer(
+ getRequiredEnv('LAMINAR_URL').fold(({ isLeft, value }) => (isLeft ? DEFAULT_CI_SERVER : value)),
+ ),
+ private readonly healthCheckActivity: IHealthCheckActivity = new HealthCheckActivityImpl(healthCheck),
+ private readonly jobHookActivity: IJobHookActivity = new JobHookActivityImpl(jobQueuer),
+ private readonly fourOhFourActivity: IFourOhFourActivity = new FourOhFourActivityImpl(),
+ ) {}
- private route(req: ITraceable<PenguenoRequest, ServerTrace>) {
- const url = new URL(req.get().url);
- if (url.pathname === "/health") {
- return this.healthCheckActivity.checkHealth(req);
+ private route(req: ITraceable<PenguenoRequest, ServerTrace>) {
+ const url = new URL(req.get().url);
+ if (url.pathname === '/health') {
+ return this.healthCheckActivity.checkHealth(req);
+ }
+ if (url.pathname === '/job') {
+ return this.jobHookActivity.processHook(req);
+ }
+ return this.fourOhFourActivity.fourOhFour(req);
}
- if (url.pathname === "/job") {
- return this.jobHookActivity.processHook(req);
- }
- return this.fourOhFourActivity.fourOhFour(req);
- }
- public serve(req: Request): Promise<Response> {
- return PenguenoRequest.from(req)
- .bimap(TraceUtil.withClassTrace(this))
- .map((req) => this.route(req))
- .get();
- }
+ public serve(req: Request): Promise<Response> {
+ return PenguenoRequest.from(req)
+ .bimap(TraceUtil.withClassTrace(this))
+ .map((req) => this.route(req))
+ .get();
+ }
}