feat: add pr view and checks (task 0009)
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`.
This commit was merged in pull request #9.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { PullReview } from "gitea-js";
|
||||
import type { PullReview, PullReviewComment } from "gitea-js";
|
||||
import type { GiteaClient } from "./client.js";
|
||||
import type { RepoContext } from "./context.js";
|
||||
import { classifyHttpError } from "./errors.js";
|
||||
@@ -47,6 +47,24 @@ export function reviewDecision(reviews: PullReview[]): ReviewDecision {
|
||||
return "required";
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a PR's reviews. One HTTP call per PR — `pr list` issues these in
|
||||
* parallel across the rows it renders, and `pr view` fetches them alongside the
|
||||
* PR itself (ADR 0006).
|
||||
*/
|
||||
export async function fetchReviews(
|
||||
api: GiteaClient,
|
||||
context: RepoContext,
|
||||
number: number,
|
||||
): Promise<PullReview[]> {
|
||||
try {
|
||||
const response = await api.repos.repoListPullReviews(context.owner, context.name, number);
|
||||
return response.data ?? [];
|
||||
} catch (error) {
|
||||
throw classifyHttpError(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a PR's reviews and reduce them to its reviewDecision. One HTTP call per
|
||||
* PR — `pr list` issues these in parallel across the rows it renders (ADR 0006).
|
||||
@@ -56,12 +74,28 @@ export async function fetchReviewDecision(
|
||||
context: RepoContext,
|
||||
number: number,
|
||||
): Promise<ReviewDecision> {
|
||||
let reviews: PullReview[];
|
||||
return reviewDecision(await fetchReviews(api, context, number));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a single review's inline (diff) comments. `pr view --reviews` issues one
|
||||
* of these per review, in parallel, to attach each review's comments to it.
|
||||
*/
|
||||
export async function fetchReviewComments(
|
||||
api: GiteaClient,
|
||||
context: RepoContext,
|
||||
number: number,
|
||||
reviewId: number,
|
||||
): Promise<PullReviewComment[]> {
|
||||
try {
|
||||
const response = await api.repos.repoListPullReviews(context.owner, context.name, number);
|
||||
reviews = response.data ?? [];
|
||||
const response = await api.repos.repoGetPullReviewComments(
|
||||
context.owner,
|
||||
context.name,
|
||||
number,
|
||||
reviewId,
|
||||
);
|
||||
return response.data ?? [];
|
||||
} catch (error) {
|
||||
throw classifyHttpError(error);
|
||||
}
|
||||
return reviewDecision(reviews);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user