8000 refactor: one sentence per plural by dominikwozniak · Pull Request #95 · 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
8000 13 changes: 11 additions & 2 deletions src/adapters/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ const git = (args: ReadonlyArray<string>) =>
})
)

/**
* `n` commits, which is the one thing this file counts out loud.
*
* It is said twice - before a session is cut and before one is taken away -
* and about the same commits both times: the ones the pull request's head does
* not have.
*/
const commits = (n: number): string => `${n} commit${n === 1 ? "" : "s"}`

/** A checkout cut for one run, and the commit it stands on. */
export interface Worktree {
readonly directory: string
Expand Down Expand Up @@ -224,7 +233,7 @@ export const standingWorktree = Effect.fn("git.standingWorktree")(function* (
return yield* new WorktreeHeld({
directory,
detail:
`The last fix session on ${repo}#${number} left ${ahead} commit${ahead === 1 ? "" : "s"} ` +
`The last fix session on ${repo}#${number} left ${commits(ahead)} ` +
`that the pull request's head does not have. Push them or drop them before opening another session.`
})
}
Expand Down Expand Up @@ -466,7 +475,7 @@ export const holding = Effect.fn("git.holding")(function* (repo: stri 10BC8 ng, number:
? clear
: ({
_tag: "held",
detail: `${ahead} commit${ahead === 1 ? "" : "s"} that the pull request's head does not have`
detail: `${commits(ahead)} that the pull request's head does not have`
} satisfies Holding)
})

Expand Down
3 changes: 2 additions & 1 deletion src/cli/findings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CliError, Command, Flag } from "effect/unstable/cli"
import type { ConfigFile } from "#adapters/config.ts"
import { read as readConfig, settingsFor } from "#adapters/config.ts"
import { named, prArgument } from "#cli/pr.ts"
import { rule } from "#cli/row.ts"
import { asUserError } from "#cli/sweep.ts"
import { count, table } from "#cli/table.ts"
import type { Findings } from "#domain/findings.ts"
Expand Down Expand Up @@ -40,7 +41,7 @@ export const header = (run: ReviewRun, found: Findings, blocksOn: Severity): str
export const lines = (found: Findings): ReadonlyArray<string> =>
table(
found.findings.map((finding) => [`${finding.file}:${finding.line}`, finding.severity, finding.summary]),
" │ "
rule
)

/**
Expand Down
2 changes: 1 addition & 1 deletion src/cli/sweep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export const sweepCommand = Command.make(
yield* Console.log(
report.repos.length === 0
? "No repositories registered. Run dw-mc init inside a repository to register it."
: `Swept ${count(report.facts.length, "pull request")} across ${report.repos.length === 1 ? "1 repository" : `${report.repos.length} repositories`}`
: `Swept ${count(report.facts.length, "pull request")} across ${repositories(report.repos.length)}`
)
yield* printTroubles(report.troubles)
},
Expand Down
12 changes: 11 additions & 1 deletion src/domain/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ export const order: ReadonlyArray<Bucket> = ["needs-me", "needs-review-run", "wa
*/
export const unanswered = "a comment I have not answered"

/**
* Why a PR is mine to move when a review run found something that withholds
* the stamp.
*
* It is named for the reason `unanswered` is: `dw-mc stamp` says this same
* sentence about this same number, and two spellings of it would be two
* answers to what a blocking finding is worth.
*/
export const blockedBy = (n: number): string => `${n} blocking finding${n === 1 ? "" : "s"}`

/**
* The first of the rules that makes a PR mine to move, or null when none
* does. The order is the order I would fix them in: a conflict makes every
Expand All @@ -86,7 +96,7 @@ const needsMe = (facts: Facts): string | null => {
return "changes requested"
}
if (facts.blockingFindings > 0) {
return `${facts.blockingFindings} blocking finding${facts.blockingFindings === 1 ? "" : "s"}`
return blockedBy(facts.blockingFindings)
}
if (isAfter(facts.newestHumanCommentAt, later(facts.myLastCommentAt, facts.myLastCommitAt))) {
return unanswered
Expand Down
3 changes: 2 additions & 1 deletion src/domain/stamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Effect, Option, Schema } from "effect"

import { prKey, remembered, storeFor } from "#adapters/store.ts"
import type { Facts } from "#domain/bucket.ts"
import { blockedBy } from "#domain/bucket.ts"

/** My local mark that a tracked PR has passed my bar, and what it rests on. */
export interface Stamp {
Expand Down Expand Up @@ -72,7 +73,7 @@ export const stampFor = (facts: Stampable, withdrawnAt: string | null): Stamp =>
return withheld("no review run on this head")
}
if (facts.blockingFindings > 0) {
return withheld(`${facts.blockingFindings} blocking finding${facts.blockingFindings === 1 ? "" : "s"}`)
return withheld(blockedBy(facts.blockingFindings))
}
const ci = whyNotGreen[facts.checks]
if (ci !== null) {
Expand Down
Loading
0