Skip to content

Commit 43347a6

Browse files
committed
feat(code): add PR comments to local tasks
1 parent ac10d2a commit 43347a6

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

apps/code/src/renderer/features/code-review/components/ReviewPage.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { useDiffViewerStore } from "@features/code-editor/stores/diffViewerStore";
12
import {
23
useBranchChangedFiles,
34
usePrChangedFiles,
45
} from "@features/git-interaction/hooks/useGitQueries";
6+
import { usePrDetails } from "@features/git-interaction/hooks/usePrDetails";
57
import { makeFileKey } from "@features/git-interaction/utils/fileKey";
68
import { usePanelLayoutStore } from "@features/panels/store/panelLayoutStore";
79
import { useCwd } from "@features/sidebar/hooks/useCwd";
@@ -15,6 +17,7 @@ import { useMemo } from "react";
1517
import { useEffectiveDiffSource } from "../hooks/useEffectiveDiffSource";
1618
import { useReviewDiffs } from "../hooks/useReviewDiffs";
1719
import type { DiffOptions } from "../types";
20+
import type { PrCommentThread } from "../utils/prCommentAnnotations";
1821
import type { ResolvedDiffSource } from "../utils/resolveDiffSource";
1922
import { InteractiveFileDiff } from "./InteractiveFileDiff";
2023
import { LazyDiff } from "./LazyDiff";
@@ -54,6 +57,14 @@ export function ReviewPage({ task }: ReviewPageProps) {
5457
prSourceAvailable,
5558
} = useEffectiveDiffSource(taskId);
5659

60+
const showReviewComments = useDiffViewerStore((s) => s.showReviewComments);
61+
const { commentThreads } = usePrDetails(prUrl, {
62+
includeComments: isReviewOpen && showReviewComments,
63+
});
64+
const effectiveCommentThreads = showReviewComments
65+
? commentThreads
66+
: undefined;
67+
5768
const isLocalActive = isReviewOpen && effectiveSource === "local";
5869

5970
const {
@@ -103,6 +114,8 @@ export function ReviewPage({ task }: ReviewPageProps) {
103114
effectiveSource={effectiveSource}
104115
branchSourceAvailable={branchSourceAvailable}
105116
prSourceAvailable={prSourceAvailable}
117+
prUrl={prUrl}
118+
commentThreads={effectiveCommentThreads}
106119
/>
107120
);
108121
}
@@ -117,6 +130,7 @@ export function ReviewPage({ task }: ReviewPageProps) {
117130
effectiveSource={effectiveSource}
118131
branchSourceAvailable={branchSourceAvailable}
119132
prSourceAvailable={prSourceAvailable}
133+
commentThreads={effectiveCommentThreads}
120134
/>
121135
);
122136
}
@@ -130,6 +144,8 @@ export function ReviewPage({ task }: ReviewPageProps) {
130144
revealFile,
131145
getDeferredReason,
132146
openFile,
147+
prUrl,
148+
commentThreads: effectiveCommentThreads,
133149
};
134150

135151
return (
@@ -192,6 +208,8 @@ function BranchReviewPage({
192208
effectiveSource,
193209
branchSourceAvailable,
194210
prSourceAvailable,
211+
prUrl,
212+
commentThreads,
195213
}: {
196214
task: Task;
197215
branch: string;
@@ -201,6 +219,8 @@ function BranchReviewPage({
201219
effectiveSource: ResolvedDiffSource;
202220
branchSourceAvailable: boolean;
203221
prSourceAvailable: boolean;
222+
prUrl: string | null;
223+
commentThreads?: Map<number, PrCommentThread>;
204224
}) {
205225
const taskId = task.id;
206226

@@ -235,11 +255,13 @@ function BranchReviewPage({
235255
<RemoteDiffList
236256
files={files}
237257
taskId={taskId}
258+
prUrl={prUrl}
238259
options={reviewState.diffOptions}
239260
collapsedFiles={reviewState.collapsedFiles}
240261
toggleFile={reviewState.toggleFile}
241262
revealFile={reviewState.revealFile}
242263
getDeferredReason={reviewState.getDeferredReason}
264+
commentThreads={commentThreads}
243265
/>
244266
</ReviewShell>
245267
);
@@ -253,6 +275,7 @@ function PrReviewPage({
253275
effectiveSource,
254276
branchSourceAvailable,
255277
prSourceAvailable,
278+
commentThreads,
256279
}: {
257280
task: Task;
258281
prUrl: string;
@@ -261,6 +284,7 @@ function PrReviewPage({
261284
effectiveSource: ResolvedDiffSource;
262285
branchSourceAvailable: boolean;
263286
prSourceAvailable: boolean;
287+
commentThreads?: Map<number, PrCommentThread>;
264288
}) {
265289
const taskId = task.id;
266290

@@ -298,6 +322,7 @@ function PrReviewPage({
298322
toggleFile={reviewState.toggleFile}
299323
revealFile={reviewState.revealFile}
300324
getDeferredReason={reviewState.getDeferredReason}
325+
commentThreads={commentThreads}
301326
/>
302327
</ReviewShell>
303328
);
@@ -324,6 +349,8 @@ interface FileDiffListProps {
324349
revealFile: (key: string) => void;
325350
getDeferredReason: (key: string) => DeferredReason | null;
326351
openFile: (taskId: string, path: string, preview: boolean) => void;
352+
prUrl: string | null;
353+
commentThreads?: Map<number, PrCommentThread>;
327354
}
328355

329356
function FileDiffList({
@@ -337,6 +364,8 @@ function FileDiffList({
337364
revealFile,
338365
getDeferredReason,
339366
openFile,
367+
prUrl,
368+
commentThreads,
340369
}: FileDiffListProps) {
341370
return files.map((fileDiff) => {
342371
const filePath = fileDiff.name ?? fileDiff.prevName ?? "";
@@ -369,6 +398,8 @@ function FileDiffList({
369398
repoPath={repoPath}
370399
options={{ ...diffOptions, collapsed: isCollapsed }}
371400
taskId={taskId}
401+
prUrl={prUrl}
402+
commentThreads={commentThreads}
372403
renderCustomHeader={(fd) => (
373404
<DiffFileHeader
374405
fileDiff={fd}

0 commit comments

Comments
 (0)