The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { PullRequestActivity, PullRequestDetail } from "@t3tools/contracts"; |
| 2 | import type { ReviewGuideGenerationInput } from "@t3tools/provider-core/server/textGeneration"; |
| 3 | |
| 4 | const SETTLED_REMARK_CHARS = 200; |
| 5 | |
| 6 | function oneLine(text: string): string { |
| 7 | const flat = text |
| 8 | .replace(/<!--[\s\S]*?-->/g, "") |
| 9 | .replace(/\s+/g, " ") |
| 10 | .trim(); |
| 11 | return flat.length > SETTLED_REMARK_CHARS ? `${flat.slice(0, SETTLED_REMARK_CHARS)}…` : flat; |
| 12 | } |
| 13 | |
| 14 | function settledReviewSummary(activity: PullRequestActivity): string { |
| 15 | return activity.reviewThreads |
| 16 | .filter((thread) => thread.isResolved || thread.isOutdated) |
| 17 | .flatMap((thread) => { |
| 18 | const opener = thread.comments[0]; |
| 19 | if (opener === undefined) return []; |
| 20 | const who = opener.author?.login ?? "ghost"; |
| 21 | const state = thread.isResolved ? "resolved" : "outdated"; |
| 22 | return [`- ${thread.path} (${state}, ${who}): ${oneLine(opener.body)}`]; |
| 23 | }) |
| 24 | .join("\n"); |
| 25 | } |
| 26 | |
| 27 | export function reviewGuideInputFromPullRequest( |
| 28 | detail: PullRequestDetail, |
| 29 | activity: PullRequestActivity, |
| 30 | baseCommit: string, |
| 31 | ): Omit<ReviewGuideGenerationInput, "cwd" | "modelSelection"> { |
| 32 | return { |
| 33 | number: detail.number, |
| 34 | title: detail.title, |
| 35 | description: detail.body, |
| 36 | baseBranch: detail.baseBranch, |
| 37 | baseCommit, |
| 38 | settledReview: settledReviewSummary(activity), |
| 39 | }; |
| 40 | } |