8000 refactor(review): write the runs namespace from its own module by dominikwozniak · Pull Request #126 · dominikwozniak/dw-mc · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions src/cli/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { Reads } from "#adapters/heartbeat.ts"
import { beating } from "#adapters/heartbeat.ts"
import { announce } from "#adapters/notify.ts"
import { Paint } from "#adapters/paint.ts"
import { stateDirectory, storeFor, textStoreFor } from "#adapters/store.ts"
import { stateDirectory } from "#adapters/store.ts"
import { block, following, indent, print } from "#cli/block.ts"
import { asUserError, userFacingAndGit } from "#cli/exit.ts"
import { lines, summary } from "#cli/findings.ts"
Expand All @@ -19,20 +19,8 @@ import { count } from "#cli/table.ts"
import { asMarkdown, jsonSchema, Reported } from "#domain/findings.ts"
import type { Reviewing } from "#domain/persona.ts"
import { turnFor } from "#domain/persona.ts"
import type { Asked, Outcome } from "#domain/review.ts"
import {
LastReviewed,
lastRun,
latestKey,
detailOf,
reportDocument,
reportedBy,
reportKey,
ReviewRun,
runKey,
short,
skippedSince
} from "#domain/review.ts"
import type { Asked, Outcome, ReviewRun } from "#domain/review.ts"
import { detailOf, lastRun, recordRun, reportedBy, short, skippedSince } from "#domain/review.ts"
import type { ReviewTurn } from "#terms/review.ts"
import { Effort } from "#terms/review.ts"

Expand Down Expand Up @@ -328,10 +316,6 @@ export const review = Command.make(
)

const ranAt = yield* DateTime.now
const runs = yield* storeFor("runs", ReviewRun)
const latest = yield* storeFor("runs", LastReviewed)
const reports = yield* textStoreFor("runs")

const got = ran.ran
const run: ReviewRun = {
repo,
Expand All @@ -343,9 +327,7 @@ export const review = Command.make(
ranAt,
outcome: got.outcome
}
yield* runs.set(runKey(repo, number, run.head), run)
yield* latest.set(latestKey(repo, number), { head: run.head })
yield* reports.set(reportKey(repo, number, run.head), reportDocument(run, view.title, got.prose ?? ""))
yield* recordRun(run, view.title, got.prose ?? "")

const detail = detailOf(run)
const found = detail === null ? reportedBy(run) : null
Expand Down
20 changes: 19 additions & 1 deletion src/domain/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { matchesGlob } from "node:path"

import { DateTime, Effect, Option, Schema } from "effect"

import { prKey, remembered, storeFor } from "#adapters/store.ts"
import { prKey, remembered, storeFor, textStoreFor } from "#adapters/store.ts"
import type { Findings } from "#domain/findings.ts"
import { blocking, Finding, Verdict } from "#domain/findings.ts"
import type { Severity } from "#terms/review.ts"
Expand Down Expand Up @@ -104,6 +104,24 @@ export const lastRun = Effect.fn("review.lastRun")(function* (repo: string, numb
return Option.isNone(at) ? Option.none<ReviewRun>() : yield* runAt(repo, number, at.value.head)
})

/**
* Writes one review run down: the run itself, the head it was at, and its
* report as the Markdown a later reader gets.
*
* The three are one act and not three. A run recorded without its head leaves
* `lastRun` reading an index that points at nothing, and one recorded without
* its report leaves `dw-mc findings` a run it can name and cannot show.
*/
export const recordRun = Effect.fn("review.recordRun")(function* (run: ReviewRun, title: string, prose: string) {
const runs = yield* storeFor("runs", ReviewRun)
const heads = yield* storeFor("runs", LastReviewed)
const reports = yield* textStoreFor("runs")

yield* runs.set(runKey(run.repo, run.number, run.head), run)
yield* heads.set(latestKey(run.repo, run.number), { head: run.head })
yield* reports.set(reportKey(run.repo, run.number, run.head), reportDocument(run, title, prose))
})

/**
* What a run reported, or null where it reported nothing at all.
*
Expand Down
Loading
0