Skip to content

Commit 10c4718

Browse files
committed
fix(review): retain commit scopes and reconcile host changes
1 parent a5ee676 commit 10c4718

14 files changed

Lines changed: 250 additions & 256 deletions

‎apps/mobile/src/features/pull-requests/PullRequestInlineCommentScreen.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ export function PullRequestInlineCommentScreen({ route }: StaticScreenProps<Inli
9494
hostedComment = undefined;
9595
}
9696
}
97-
if (!setReviewDraftBusy(params, true)) return;
97+
if (!setReviewDraftBusy(params, true))
98+
throw new Error("Wait for the pending comment to finish saving.");
9899
locked = true;
99100
if (hostedComment && saved && body !== saved.body) {
100101
const target = pullRequestTarget(params);

‎apps/mobile/src/features/review/ReviewFileTree.tsx‎

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -194,54 +194,53 @@ export function ReviewFileTree({
194194
);
195195
}}
196196
>
197-
<Pressable
198-
accessibilityRole="button"
199-
accessibilityLabel={`${file.path}${renamed ? `, renamed from ${file.previousPath}` : ""}, ${file.unresolved ?? 0} unresolved comments`}
200-
className="min-h-[42px] flex-row items-center gap-2 rounded-xl pr-3"
201-
style={{ paddingLeft: 28 + Math.min(item.depth * 16, Math.max(0, width - 220)) }}
202-
onPress={() => onSelectFile(file.path)}
203-
>
204-
<PierreEntryIcon kind="file" path={file.path} size={18} />
205-
<View className="min-w-0 flex-1 py-1">
206-
{file.previousPath && file.previousPath !== file.path ? (
207-
<ReviewRenamePath
208-
path={file.path}
209-
previousPath={file.previousPath}
210-
directory={false}
211-
/>
212-
) : (
213-
<Text numberOfLines={1} ellipsizeMode="tail" className="text-sm">
214-
{file.path.split("/").at(-1)}
215-
</Text>
216-
)}
217-
</View>
218-
{(file.unresolved ?? 0) > 0 ? (
219-
<Text className="text-xs text-foreground-muted">{file.unresolved}</Text>
220-
) : null}
221-
<Text
222-
className={
223-
status === "A"
224-
? "text-xs text-adaptive-emerald-600-400"
225-
: status === "D"
226-
? "text-xs text-danger-foreground"
227-
: status === "R"
228-
? "text-xs text-warning-foreground"
229-
: "text-xs text-foreground-muted"
230-
}
197+
<View className="flex-row items-center">
198+
<Pressable
199+
accessibilityRole="button"
200+
accessibilityLabel={`${file.path}${renamed ? `, renamed from ${file.previousPath}` : ""}, ${file.unresolved ?? 0} unresolved comments`}
201+
className="min-h-[42px] min-w-0 flex-1 flex-row items-center gap-2 rounded-xl pr-3"
202+
style={{ paddingLeft: 28 + Math.min(item.depth * 16, Math.max(0, width - 220)) }}
203+
onPress={() => onSelectFile(file.path)}
231204
>
232-
{status}
233-
</Text>
205+
<PierreEntryIcon kind="file" path={file.path} size={18} />
206+
<View className="min-w-0 flex-1 py-1">
207+
{file.previousPath && file.previousPath !== file.path ? (
208+
<ReviewRenamePath
209+
path={file.path}
210+
previousPath={file.previousPath}
211+
directory={false}
212+
/>
213+
) : (
214+
<Text numberOfLines={1} ellipsizeMode="tail" className="text-sm">
215+
{file.path.split("/").at(-1)}
216+
</Text>
217+
)}
218+
</View>
219+
{(file.unresolved ?? 0) > 0 ? (
220+
<Text className="text-xs text-foreground-muted">{file.unresolved}</Text>
221+
) : null}
222+
<Text
223+
className={
224+
status === "A"
225+
? "text-xs text-adaptive-emerald-600-400"
226+
: status === "D"
227+
? "text-xs text-danger-foreground"
228+
: status === "R"
229+
? "text-xs text-warning-foreground"
230+
: "text-xs text-foreground-muted"
231+
}
232+
>
233+
{status}
234+
</Text>
235+
</Pressable>
234236
{showViewedCheckbox ? (
235237
<Pressable
236238
accessibilityRole="checkbox"
237239
accessibilityLabel={`Mark ${file.path} as ${file.reviewed ? "unviewed" : "viewed"}`}
238240
accessibilityState={{ checked: file.reviewed === true, disabled: !onSetViewed }}
239241
disabled={!onSetViewed}
240242
className="min-h-11 min-w-11 items-center justify-center"
241-
onPress={(event) => {
242-
event.stopPropagation();
243-
onSetViewed?.([file.path], !file.reviewed);
244-
}}
243+
onPress={() => onSetViewed?.([file.path], !file.reviewed)}
245244
>
246245
<View
247246
className={
@@ -266,7 +265,7 @@ export function ReviewFileTree({
266265
tintColorClassName="accent-adaptive-emerald-600-400"
267266
/>
268267
) : null}
269-
</Pressable>
268+
</View>
270269
</Menu>
271270
);
272271
}}

‎apps/mobile/src/features/review/workingChangesTreeState.test.ts‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎apps/mobile/src/features/review/workingChangesTreeState.ts‎

Lines changed: 0 additions & 37 deletions
This file was deleted.

‎apps/server/src/pullRequest/PullRequestService.test.ts‎

Lines changed: 40 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4349,43 +4349,59 @@ it.effect.each([false, true])(
43494349
}),
43504350
);
43514351

4352-
it.effect(
4353-
"refuses ranged comments before dispatching to a host that supports only single lines",
4354-
() =>
4352+
it.effect.each(["single-line", "reversed"] as const)(
4353+
"refuses invalid ranges before dispatching a review or draft comment (%s)",
4354+
(kind) =>
43554355
Effect.gen(function* () {
43564356
let submitted = false;
4357+
const provider = fakePullRequestProvider(SourceControlProviderKind.make("github"));
43574358
const service = yield* makeService({
43584359
projects: [
43594360
project({ id: "p1", title: "web", workspaceRoot: "/w", repository: "acme/web" }),
43604361
],
43614362
providers: [
4362-
fakePullRequestProvider(SourceControlProviderKind.make("github"), {
4363+
{
4364+
...provider,
4365+
capabilities: {
4366+
...provider.capabilities,
4367+
review: {
4368+
...provider.capabilities.review,
4369+
draftComment: true,
4370+
rangeComment: kind === "reversed",
4371+
},
4372+
},
43634373
submitReview: () =>
43644374
Effect.sync(() => {
43654375
submitted = true;
43664376
}),
4367-
}),
4377+
saveDraftComment: () =>
4378+
Effect.sync(() => {
4379+
submitted = true;
4380+
return {
4381+
reviewId: "review",
4382+
commentId: "comment",
4383+
url: "https://github.com/acme/web/pull/1#discussion_r1",
4384+
};
4385+
}),
4386+
},
43684387
],
43694388
});
4370-
const error = yield* service
4371-
.submitReview({
4372-
projectId: "p1" as ProjectId,
4373-
repository: "acme/web",
4374-
number: 1,
4375-
verdict: "comment",
4376-
body: "",
4377-
comments: [
4378-
{
4379-
path: "a.ts",
4380-
body: "Range",
4381-
position: { kind: "added", newLine: 8 },
4382-
startPosition: { kind: "added", newLine: 3 },
4383-
},
4384-
],
4385-
})
4386-
.pipe(Effect.flip);
4387-
assert.strictEqual(error._tag, "PullRequestOperationError");
4388-
assert.isFalse(submitted);
4389+
const ref = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 };
4390+
const comment = {
4391+
path: "a.ts",
4392+
body: "Range",
4393+
position: { kind: "added" as const, newLine: 8 },
4394+
startPosition: { kind: "added" as const, newLine: kind === "reversed" ? 12 : 3 },
4395+
};
4396+
for (const operation of [
4397+
service.submitReview({ ...ref, verdict: "comment", body: "", comments: [comment] }),
4398+
service.saveDraftComment({ ...ref, comment }),
4399+
]) {
4400+
const error = yield* operation.pipe(Effect.flip);
4401+
assert.strictEqual(error._tag, "PullRequestOperationError");
4402+
if (kind === "reversed") assert.include(error.message, "reversed");
4403+
assert.isFalse(submitted);
4404+
}
43894405
}),
43904406
);
43914407

@@ -4487,34 +4503,6 @@ it.effect(
44874503
}),
44884504
);
44894505

4490-
it.effect("forwards private reply ownership to the destination provider", () =>
4491-
Effect.gen(function* () {
4492-
const calls: string[] = [];
4493-
const service = yield* makeService({
4494-
projects: [
4495-
project({ id: "p1", title: "t3code", workspaceRoot: "/a", repository: "pingdotgg/t3code" }),
4496-
],
4497-
providers: [
4498-
fakePullRequestProvider(SourceControlProviderKind.make("github"), {
4499-
replyToThread: (input) =>
4500-
Effect.sync(() => {
4501-
calls.push(`${input.threadId}:${input.pendingReviewId}:${input.body}`);
4502-
}),
4503-
}),
4504-
],
4505-
});
4506-
yield* service.replyToThread({
4507-
projectId: "p1" as ProjectId,
4508-
repository: "pingdotgg/t3code",
4509-
number: 1,
4510-
threadId: "t1",
4511-
pendingReviewId: "private-review",
4512-
body: "Follow-up",
4513-
});
4514-
expect(calls).toEqual(["t1:private-review:Follow-up"]);
4515-
}),
4516-
);
4517-
45184506
it.effect.each(["commit", "credential", "expiry", "refresh"] as const)(
45194507
"keeps cold metadata membership in its original scope through an in-flight %s",
45204508
(boundary) =>

‎apps/server/src/pullRequest/PullRequestService.ts‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,19 @@ function reviewPositionAnchor(position: PullRequestReviewPosition) {
324324
}
325325
}
326326

327+
function isReversedReviewRange({
328+
position,
329+
startPosition,
330+
}: {
331+
readonly position: PullRequestReviewPosition;
332+
readonly startPosition?: PullRequestReviewPosition | undefined;
333+
}) {
334+
if (startPosition === undefined) return false;
335+
const end = reviewPositionAnchor(position);
336+
const start = reviewPositionAnchor(startPosition);
337+
return start.side === end.side && start.line > end.line;
338+
}
339+
327340
const VERDICT_LABELS: Record<PullRequestReviewVerdict, string> = {
328341
comment: "review",
329342
approve: "approve",
@@ -2391,6 +2404,11 @@ export const make = Effect.gen(function* () {
23912404
operation: "saveDraftComment",
23922405
detail: "This host cannot save a comment range.",
23932406
});
2407+
if (isReversedReviewRange(input.comment))
2408+
return yield* new PullRequestOperationError({
2409+
operation: "saveDraftComment",
2410+
detail: "The selected comment range is reversed. Select the lines again.",
2411+
});
23942412
const viewer = yield* viewerPermissionsOf(project, input, "saveDraftComment");
23952413
if (!viewer.comment)
23962414
return yield* new PullRequestOperationError({
@@ -2458,13 +2476,8 @@ export const make = Effect.gen(function* () {
24582476
return refuse(
24592477
"This host supports comments on a single line. Select one line to comment.",
24602478
);
2461-
for (const { position, startPosition } of input.comments) {
2462-
if (startPosition === undefined) continue;
2463-
const end = reviewPositionAnchor(position);
2464-
const start = reviewPositionAnchor(startPosition);
2465-
if (start.side === end.side && start.line > end.line)
2466-
return refuse("The selected comment range is reversed. Select the lines again.");
2467-
}
2479+
if (input.comments.some(isReversedReviewRange))
2480+
return refuse("The selected comment range is reversed. Select the lines again.");
24682481
// A verdict with nothing attached to it is a request every host rejects, and doing so
24692482
// here says which of the two is missing rather than reporting the host's refusal.
24702483
if (

0 commit comments

Comments
 (0)