Skip to content
Myr

classify.ts

This file

Path

apps/platform/src/workflows/on-push/classify.ts

91 lines · 2.3 KiB · TypeScript

Last changed by

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

History of this file

Take 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–91why, one step back
1import { Brand } from "@repo/brand";
2import { notesRef } from "@repo/git/notes";3import { RefNameText } from "@repo/protocol/domain/common";4import { AskId, CommitSha, ProjectName } from "@repo/protocol/ids";5import { Schema } from "effect";67import { RepoKind } from "../../repo-names.ts";8import { isZero } from "./event.ts";9import type { OnPushEvent } from "./event.ts";1011export const IgnoredReason = Schema.Literals([12 "own landing",13 "bookkeeping ref",14 "seen",15 "unknown repo",16 "not main",17 "deleted ref",18]);1920export type IgnoredReason = typeof IgnoredReason.Type;2122export const PushVerdict = Schema.TaggedUnion({23 ForkPush: { ask: AskId, head: CommitSha, project: ProjectName },24 Ignored: { reason: IgnoredReason },25 Stray: {26 after: CommitSha,27 before: CommitSha,28 project: ProjectName,29 ref: RefNameText,30 },31});3233export type PushVerdict = typeof PushVerdict.Type;3435export interface PushFacts {36 readonly repo: RepoKind;37 readonly landed: ReadonlySet<CommitSha>;38 readonly seen: boolean;39}4041export const mainRef = RefNameText.make("refs/heads/main");4243export const isBookkeeping = (ref: string): boolean =>44 ref.startsWith(Brand.refsPrefix) || ref === notesRef;4546const ignored = (reason: IgnoredReason): PushVerdict =>47 PushVerdict.cases.Ignored.make({ reason });4849export const classifyPush = (50 event: OnPushEvent,51 facts: PushFacts52): PushVerdict => {53 const { after, before, ref } = event.payload;5455 return RepoKind.$match(facts.repo, {56 Canonical: ({ project }) => {57 if (isBookkeeping(ref)) {58 return ignored("bookkeeping ref");59 }6061 if (ref !== mainRef) {62 return ignored("not main");63 }6465 return facts.landed.has(after)66 ? ignored("own landing")67 : PushVerdict.cases.Stray.make({68 after,69 before,70 project,71 ref: mainRef,72 });73 },74 ClaimFork: ({ ask, project }) => {75 if (isBookkeeping(ref)) {76 return ignored("bookkeeping ref");77 }7879 if (isZero(after)) {80 return ignored("deleted ref");81 }8283 return facts.seen84 ? ignored("seen")85 : PushVerdict.cases.ForkPush.make({ ask, head: after, project });86 },87 Unknown: () => ignored("unknown repo"),88 WorkingFork: () =>89 isBookkeeping(ref) ? ignored("bookkeeping ref") : ignored("not main"),90 });91};