Skip to content

Commit 52f5e99

Browse files
committed
feat(code): add PR comments to local tasks
1 parent 23bb331 commit 52f5e99

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 {
@@ -108,6 +119,8 @@ export function ReviewPage({ task }: ReviewPageProps) {
108119
effectiveSource={effectiveSource}
109120
branchSourceAvailable={branchSourceAvailable}
110121
prSourceAvailable={prSourceAvailable}
122+
prUrl={prUrl}
123+
commentThreads={effectiveCommentThreads}
111124
/>
112125
);
113126
}
@@ -122,6 +135,7 @@ export function ReviewPage({ task }: ReviewPageProps) {
122135
effectiveSource={effectiveSource}
123136
branchSourceAvailable={branchSourceAvailable}
124137
prSourceAvailable={prSourceAvailable}
138+
commentThreads={effectiveCommentThreads}
125139
/>
126140
);
127141
}
@@ -135,6 +149,8 @@ export function ReviewPage({ task }: ReviewPageProps) {
135149
revealFile,
136150
getDeferredReason,
137151
openFile,
152+
prUrl,
153+
commentThreads: effectiveCommentThreads,
138154
};
139155

140156
return (
@@ -201,6 +217,8 @@ function BranchReviewPage({
201217
effectiveSource,
202218
branchSourceAvailable,
203219
prSourceAvailable,
220+
prUrl,
221+
commentThreads,
204222
}: {
205223
task: Task;
206224
branch: string;
@@ -210,6 +228,8 @@ function BranchReviewPage({
210228
effectiveSource: ResolvedDiffSource;
211229
branchSourceAvailable: boolean;
212230
prSourceAvailable: boolean;
231+
prUrl: string | null;
232+
commentThreads?: Map<number, PrCommentThread>;
213233
}) {
214234
const taskId = task.id;
215235

@@ -244,11 +264,13 @@ function BranchReviewPage({
244264
<RemoteDiffList
245265
files={files}
246266
taskId={taskId}
267+
prUrl={prUrl}
247268
options={reviewState.diffOptions}
248269
collapsedFiles={reviewState.collapsedFiles}
249270
toggleFile={reviewState.toggleFile}
250271
revealFile={reviewState.revealFile}
251272
getDeferredReason={reviewState.getDeferredReason}
273+
commentThreads={commentThreads}
252274
/>
253275
</ReviewShell>
254276
);
@@ -262,6 +284,7 @@ function PrReviewPage({
262284
effectiveSource,
263285
branchSourceAvailable,
264286
prSourceAvailable,
287+
commentThreads,
265288
}: {
266289
task: Task;
267290
prUrl: string;
@@ -270,6 +293,7 @@ function PrReviewPage({
270293
effectiveSource: ResolvedDiffSource;
271294
branchSourceAvailable: boolean;
272295
prSourceAvailable: boolean;
296+
commentThreads?: Map<number, PrCommentThread>;
273297
}) {
274298
const taskId = task.id;
275299

@@ -307,6 +331,7 @@ function PrReviewPage({
307331
toggleFile={reviewState.toggleFile}
308332
revealFile={reviewState.revealFile}
309333
getDeferredReason={reviewState.getDeferredReason}
334+
commentThreads={commentThreads}
310335
/>
311336
</ReviewShell>
312337
);
@@ -334,6 +359,8 @@ interface FileDiffListProps {
334359
revealFile: (key: string) => void;
335360
getDeferredReason: (key: string) => DeferredReason | null;
336361
openFile: (taskId: string, path: string, preview: boolean) => void;
362+
prUrl: string | null;
363+
commentThreads?: Map<number, PrCommentThread>;
337364
}
338365

339366
function FileDiffList({
@@ -348,6 +375,8 @@ function FileDiffList({
348375
revealFile,
349376
getDeferredReason,
350377
openFile,
378+
prUrl,
379+
commentThreads,
351380
}: FileDiffListProps) {
352381
return files.map((fileDiff) => {
353382
const filePath = fileDiff.name ?? fileDiff.prevName ?? "";
@@ -382,6 +411,8 @@ function FileDiffList({
382411
skipExpansion={skipExpansion}
383412
options={{ ...diffOptions, collapsed: isCollapsed }}
384413
taskId={taskId}
414+
prUrl={prUrl}
415+
commentThreads={commentThreads}
385416
renderCustomHeader={(fd) => (
386417
<DiffFileHeader
387418
fileDiff={fd}

0 commit comments

Comments
 (0)