Skip to content

Commit 77e0743

Browse files
committed
fix(git): reuse active thread for inline PR review
1 parent 8ca26d2 commit 77e0743

3 files changed

Lines changed: 37 additions & 4 deletions

File tree

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,8 @@ function MainApp() {
18331833
runPullRequestReview,
18341834
} = usePullRequestReviewActions({
18351835
activeWorkspace,
1836+
activeThreadId,
1837+
reviewDeliveryMode: appSettings.reviewDeliveryMode,
18361838
pullRequest: selectedPullRequest,
18371839
pullRequestDiffs: gitPullRequestDiffs,
18381840
pullRequestComments: gitPullRequestComments,

src/features/git/hooks/usePullRequestReviewActions.test.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ function renderActions(
5555
) {
5656
const options: Parameters<typeof usePullRequestReviewActions>[0] = {
5757
activeWorkspace: workspace,
58+
activeThreadId: "thread-active",
59+
reviewDeliveryMode: "detached",
5860
pullRequest,
5961
pullRequestDiffs: diffs,
6062
pullRequestComments: comments,
@@ -68,7 +70,7 @@ function renderActions(
6870
}
6971

7072
describe("usePullRequestReviewActions", () => {
71-
it("always starts a new thread for PR review", async () => {
73+
it("starts a new thread for detached PR review", async () => {
7274
const { result, options } = renderActions();
7375

7476
await act(async () => {
@@ -131,4 +133,23 @@ describe("usePullRequestReviewActions", () => {
131133
expect(options.startThreadForWorkspace).toHaveBeenCalledTimes(1);
132134
expect(options.sendUserMessageToThread).toHaveBeenCalledTimes(1);
133135
});
136+
137+
it("reuses the active thread for inline PR review", async () => {
138+
const { result, options } = renderActions({
139+
activeThreadId: "thread-active",
140+
reviewDeliveryMode: "inline",
141+
});
142+
143+
await act(async () => {
144+
await result.current.runPullRequestReview({ intent: "full" });
145+
});
146+
147+
expect(options.startThreadForWorkspace).not.toHaveBeenCalled();
148+
expect(options.sendUserMessageToThread).toHaveBeenCalledWith(
149+
workspace,
150+
"thread-active",
151+
expect.any(String),
152+
[],
153+
);
154+
});
134155
});

src/features/git/hooks/usePullRequestReviewActions.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const REVIEW_ACTIONS: PullRequestReviewAction[] = [
2121

2222
type UsePullRequestReviewActionsOptions = {
2323
activeWorkspace: WorkspaceInfo | null;
24+
activeThreadId: string | null;
25+
reviewDeliveryMode: "inline" | "detached";
2426
pullRequest: GitHubPullRequest | null;
2527
pullRequestDiffs: GitHubPullRequestDiff[];
2628
pullRequestComments: GitHubPullRequestComment[];
@@ -47,6 +49,8 @@ type RunPullRequestReviewOptions = {
4749

4850
export function usePullRequestReviewActions({
4951
activeWorkspace,
52+
activeThreadId,
53+
reviewDeliveryMode,
5054
pullRequest,
5155
pullRequestDiffs,
5256
pullRequestComments,
@@ -80,9 +84,13 @@ export function usePullRequestReviewActions({
8084
await connectWorkspace(activeWorkspace);
8185
}
8286

83-
const reviewThreadId = await startThreadForWorkspace(activeWorkspace.id, {
84-
activate: activateThread,
85-
});
87+
const reuseActiveThread =
88+
reviewDeliveryMode === "inline" && Boolean(activeThreadId);
89+
const reviewThreadId = reuseActiveThread
90+
? activeThreadId
91+
: await startThreadForWorkspace(activeWorkspace.id, {
92+
activate: activateThread,
93+
});
8694
if (!reviewThreadId) {
8795
throw new Error("Failed to start a review thread.");
8896
}
@@ -113,10 +121,12 @@ export function usePullRequestReviewActions({
113121
},
114122
[
115123
activeWorkspace,
124+
activeThreadId,
116125
connectWorkspace,
117126
pullRequest,
118127
pullRequestComments,
119128
pullRequestDiffs,
129+
reviewDeliveryMode,
120130
sendUserMessageToThread,
121131
startThreadForWorkspace,
122132
],

0 commit comments

Comments
 (0)