facts.ts
This file
Path
apps/platform/src/workflows/on-push/facts.ts
98 lines · 3.0 KiB · TypeScript
Last changed by
Merge observability into mainoscabrielbefore adoption1985111
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 1–17why, one step back1import { platformHandle } from "@repo/project/attention/effects";2import type { ProjectApi } from "@repo/project/project";3import { keptEvents } from "@repo/project/project-store";4import { Projects } from "@repo/project/projects";5import { ProjectEvent } from "@repo/protocol/domain/event";6import type { AskId, CommitSha, ProjectName } from "@repo/protocol/ids";7import { Person } from "@repo/protocol/principal";8import { Effect, Option } from "effect";910import { RepoKind, repoKind } from "../../repo-names.ts";11import { isBookkeeping, mainRef } from "./classify.ts";12import type { PushFacts } from "./classify.ts";13import { isZero } from "./event.ts";14import type { OnPushEvent } from "./event.ts";1516const platform = Person.make({ handle: platformHandle });17Merge observability into mainoscabrielbefore adoption1985111
line 18why, one step back18export const projectOf = (kind: RepoKind): Option.Option<ProjectName> =>Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 19–98why, one step back19 RepoKind.$match(kind, {20 Canonical: ({ project }) => Option.some(project),21 ClaimFork: ({ project }) => Option.some(project),22 Unknown: () => Option.none(),23 WorkingFork: ({ project }) => Option.some(project),24 });2526const landedOf = (api: ProjectApi, sha: CommitSha) =>27 Effect.map(Effect.isSuccess(api.landing(platform, sha)), (landed) =>28 landed ? new Set([sha]) : new Set<CommitSha>()29 );3031const seenBy = (32 api: ProjectApi,33 push: { readonly ask: AskId; readonly head: CommitSha }34) =>35 Effect.map(api.events(0, keptEvents), (rows) =>36 rows.some(37 ({ event }) =>38 ProjectEvent.guards.Pushed(event) &&39 event.ask === push.ask &&40 event.head === push.head41 )42 );4344const nothing = (repo: RepoKind): PushFacts => ({45 landed: new Set(),46 repo,47 seen: false,48});4950export const projectFor = (event: OnPushEvent) =>51 Effect.gen(function* () {52 const kind = repoKind(event.source.repoName);53 const project = projectOf(kind);5455 if (Option.isNone(project)) {56 return Option.none();57 }5859 const api = yield* Effect.option(60 Projects.use((projects) => projects.get(project.value))61 );6263 return Option.map(api, (found) => ({ api: found, kind }));64 });6566export const factsOf = (67 event: OnPushEvent68): Effect.Effect<PushFacts, never, Projects> =>69 Effect.gen(function* () {70 const { after, ref } = event.payload;71 const found = yield* projectFor(event);7273 if (Option.isNone(found)) {74 return nothing(RepoKind.Unknown());75 }7677 const { api, kind } = found.value;78 const moved = !isZero(after) && !isBookkeeping(ref);7980 return yield* RepoKind.$match(kind, {81 Canonical: () =>82 moved && ref === mainRef83 ? Effect.map(landedOf(api, after), (landed) => ({84 ...nothing(kind),85 landed,86 }))87 : Effect.succeed(nothing(kind)),88 ClaimFork: ({ ask }) =>89 moved90 ? Effect.map(seenBy(api, { ask, head: after }), (seen) => ({91 ...nothing(kind),92 seen,93 }))94 : Effect.succeed(nothing(kind)),95 Unknown: () => Effect.succeed(nothing(kind)),96 WorkingFork: () => Effect.succeed(nothing(kind)),97 });98 });