Skip to content

Commit dd5c363

Browse files
TonybynMp4claude
andcommitted
perf(gitlab): previews and summaries skip the fork maintainer edits permission read
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9d7d3e3 commit dd5c363

4 files changed

Lines changed: 48 additions & 5 deletions

File tree

‎packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,35 @@ layer("GitLabPullRequestCli.layer", (it) => {
11871187
}),
11881188
);
11891189

1190+
it.effect("skips a fork's maintainer edits permission read when the caller opts out", () =>
1191+
Effect.gen(function* () {
1192+
mockedExecute.mockReturnValueOnce(
1193+
Effect.succeed(
1194+
output(
1195+
mergeRequestJson({
1196+
source_project_id: 40,
1197+
target_project_id: 12,
1198+
allow_collaboration: true,
1199+
}),
1200+
),
1201+
),
1202+
);
1203+
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1204+
1205+
const detail = yield* cli.getMergeRequestDetail({
1206+
cwd: "/w",
1207+
repository: "acme/web",
1208+
number: 7,
1209+
downstreamChecks: false,
1210+
maintainerEdits: false,
1211+
});
1212+
1213+
expect(detail.maintainerCanModify).toBe(true);
1214+
expect(detail.viewerCanEditMaintainerEdits).toBeUndefined();
1215+
expect(mockedExecute).toHaveBeenCalledTimes(1);
1216+
}),
1217+
);
1218+
11901219
it.effect("sends maintainer edits as allow_collaboration", () =>
11911220
Effect.gen(function* () {
11921221
mockedExecute.mockReturnValueOnce(Effect.succeed(output("{}")));

‎packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ export class GitLabPullRequestCli extends Context.Service<
254254
readonly number: number;
255255
/** `false` skips the trigger job read; the permission check before every write does. */
256256
readonly downstreamChecks?: boolean;
257+
/** `false` skips a fork's maintainer edits permission read, for views that never show it. */
258+
readonly maintainerEdits?: boolean;
257259
}) => Effect.Effect<GitLabMergeRequestDetail, GitLabPullRequestCliError>;
258260

259261
readonly getReviewDecisions: (input: {
@@ -1370,7 +1372,9 @@ export const make = Effect.gen(function* () {
13701372
const read = yield* mergeRequestDetail(input);
13711373
// Only forks have the setting, so same-project merge requests skip the extra read.
13721374
const detail =
1373-
read.maintainerCanModify === undefined || read.state !== "open"
1375+
input.maintainerEdits === false ||
1376+
read.maintainerCanModify === undefined ||
1377+
read.state !== "open"
13741378
? read
13751379
: {
13761380
...read,

‎packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,17 @@ describe("getChangeRequest base freshness", () => {
182182
};
183183

184184
it.effect.each(["getChangeRequestPreview", "getChangeRequestSummary"] as const)(
185-
"%s preserves merge request fields without fetching project settings",
185+
"%s preserves merge request fields without fetching project settings or fork permissions",
186186
(operation) =>
187187
Effect.gen(function* () {
188+
const detailInputs: Array<{ readonly maintainerEdits?: boolean }> = [];
188189
const provider = yield* make.pipe(
189190
Effect.provide(
190191
Layer.mock(GitLabPullRequestCli.GitLabPullRequestCli)({
191-
getMergeRequestDetail: () => Effect.succeed(detail),
192+
getMergeRequestDetail: (input) => {
193+
detailInputs.push(input);
194+
return Effect.succeed(detail);
195+
},
192196
getReviewDecisions: () => Effect.succeed(new Map()),
193197

194198
listMergeRequestStats: () => Effect.succeed([]),
@@ -200,6 +204,7 @@ describe("getChangeRequest base freshness", () => {
200204
expect(
201205
yield* read({ cwd: "/w", repository: "acme/web", host: "gitlab.com", number: 7 }),
202206
).toEqual(detail);
207+
expect(detailInputs.map((input) => input.maintainerEdits)).toEqual([false]);
203208
}),
204209
);
205210

‎packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,17 @@ export const make = Effect.gen(function* () {
273273

274274
// Merge settings only affect the detail panel's actions.
275275
getChangeRequestPreview: (input) =>
276-
cli.getMergeRequestDetail(input).pipe(Effect.mapError(fail("getChangeRequestPreview"))),
276+
cli
277+
.getMergeRequestDetail({ ...input, maintainerEdits: false })
278+
.pipe(Effect.mapError(fail("getChangeRequestPreview"))),
277279

278280
getChangeRequestSummary: (input) =>
279281
Effect.all(
280282
[
281-
mergeRequestWithStats(input),
283+
mergeRequestWithStats(
284+
input,
285+
cli.getMergeRequestDetail({ ...input, maintainerEdits: false }),
286+
),
282287
reviewDecisions({
283288
cwd: input.cwd,
284289
host: input.host,

0 commit comments

Comments
 (0)