Open History to see the last commit
1import type { PullRequestActivity, PullRequestDetail } from "@t3tools/contracts";
2import type { ReviewGuideGenerationInput } from "@t3tools/provider-core/server/textGeneration";
3import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations";
4
5const SETTLED_REMARK_CHARS = 200;
6
7function oneLine(text: string): string {
8 const flat = text
9 .replace(/<!--[\s\S]*?-->/g, "")
10 .replace(/\s+/g, " ")
11 .trim();
12 if (flat.length <= SETTLED_REMARK_CHARS) return flat;
13 const end = splitsSurrogatePair(flat, SETTLED_REMARK_CHARS)
14 ? SETTLED_REMARK_CHARS - 1
15 : SETTLED_REMARK_CHARS;
16 return `${flat.slice(0, end)}…`;
17}
18
19function settledReviewSummary(activity: PullRequestActivity): string {
20 return activity.reviewThreads
21 .filter((thread) => thread.isResolved || thread.isOutdated)
22 .flatMap((thread) => {
23 const opener = thread.comments[0];
24 if (opener === undefined) return [];
25 const who = opener.author?.login ?? "ghost";
26 const state = thread.isResolved ? "resolved" : "outdated";
27 return [`- ${thread.path} (${state}, ${who}): ${oneLine(opener.body)}`];
28 })
29 .join("\n");
30}
31
32export function reviewGuideInputFromPullRequest(
33 detail: PullRequestDetail,
34 activity: PullRequestActivity,
35 baseCommit: string,
36): Omit<ReviewGuideGenerationInput, "cwd" | "projectCwd" | "modelSelection"> {
37 return {
38 number: detail.number,
39 title: detail.title,
40 description: detail.body,
41 baseBranch: detail.baseBranch,
42 baseCommit,
43 settledReview: settledReviewSummary(activity),
44 };
45}