Add `pr view <n>` and `pr checks <n>`, built on the truncation machinery
and review fetches from earlier slices.
`pr view` uses the three-call fetch pattern (PR + reviews in parallel, then
the head commit's combined status) so `checks`, `comment_count`, and
`review_count` are in the default output; `--comments`, `--reviews`, and
`--full` behave as on `issue view`, with `--reviews` exposing Gitea's
`official`/`stale` fields plus per-review inline comments.
`pr checks <n>` renders the checks summary line and the `{ name, conclusion }`
rows, or the scalar no-CI message when no statuses exist.
The state→conclusion mapping and summary live in a new `src/checks.ts`;
`commentRows` is extracted into `src/comment.ts` and shared with `issue view`.
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { CommitStatus } from "gitea-js";
|
|
import { summarizeChecks } from "../src/checks.js";
|
|
|
|
describe("summarizeChecks", () => {
|
|
it("maps success commit statuses to pass checks and omits zero skipped/pending segments", () => {
|
|
const statuses = [
|
|
{ context: "build", status: "success" },
|
|
{ context: "test", status: "success" },
|
|
] as CommitStatus[];
|
|
|
|
const result = summarizeChecks(statuses);
|
|
|
|
expect(result.checks).toEqual([
|
|
{ name: "build", conclusion: "pass" },
|
|
{ name: "test", conclusion: "pass" },
|
|
]);
|
|
expect(result.summary).toBe("2 passed, 0 failed, 2 total");
|
|
});
|
|
|
|
it("maps failure, error, and warning states all to fail (warning counts as failure)", () => {
|
|
const statuses = [
|
|
{ context: "a", status: "failure" },
|
|
{ context: "b", status: "error" },
|
|
{ context: "c", status: "warning" },
|
|
] as CommitStatus[];
|
|
|
|
const result = summarizeChecks(statuses);
|
|
|
|
expect(result.checks).toEqual([
|
|
{ name: "a", conclusion: "fail" },
|
|
{ name: "b", conclusion: "fail" },
|
|
{ name: "c", conclusion: "fail" },
|
|
]);
|
|
expect(result.summary).toBe("0 passed, 3 failed, 3 total");
|
|
});
|
|
});
|