Skip to content

Commit 12b3a0c

Browse files
fix(server): preserve raw GitLab selectors through checkout routing
1 parent 964e058 commit 12b3a0c

5 files changed

Lines changed: 31 additions & 24 deletions

File tree

‎apps/server/src/mcp/toolkits/pullRequests/handlers.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ const make = Effect.gen(function* () {
270270
host: target.host,
271271
repository: target.repository,
272272
number: target.number,
273+
webUrl: null,
273274
});
274275
const url = yield* Effect.try(() => new URL(detail.url));
275276
url.username = "";
@@ -295,11 +296,12 @@ const make = Effect.gen(function* () {
295296
if (watching && before?.snapshot?.state === "merged") {
296297
return yield* new PullRequestNotOpenError({ state: "merged" });
297298
}
298-
const link = watching
299-
? yield* resolveLink(target, input, project).pipe(
300-
Effect.mapError((cause) => new PullRequestWatchFailedError({ cause })),
301-
)
302-
: undefined;
299+
const link =
300+
watching && before === undefined
301+
? yield* resolveLink(target, input, project).pipe(
302+
Effect.mapError((cause) => new PullRequestWatchFailedError({ cause })),
303+
)
304+
: undefined;
303305
yield* engine
304306
.dispatch({
305307
type: "thread.pull-request.watch",
@@ -317,7 +319,7 @@ const make = Effect.gen(function* () {
317319
host: target.host,
318320
repository: target.repository,
319321
number: target.number,
320-
url: link?.url ?? target.url,
322+
url: link?.url ?? before?.url ?? target.url,
321323
watching: watchedLink(after)?.watch !== undefined,
322324
wasWatching: before?.watch !== undefined,
323325
};

‎apps/server/src/orchestration-v2/PullRequestSyncReactor.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ export const make = Effect.gen(function* () {
278278
repository: first.link.repository,
279279
number: first.link.number,
280280
webUrl:
281-
first.link.repositoryWebUrl ??
282-
(first.link.source === "agent" ? undefined : first.link.url),
281+
first.link.repositoryWebUrl ?? (first.link.source === "agent" ? null : first.link.url),
283282
};
284283
const generation = requested.get(key);
285284
// A held merged summary is served without asking the host, so a snapshot still missing its

‎apps/server/src/orchestration-v2/PullRequestWatchReactor.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ export const make = Effect.gen(function* () {
389389
projectId: first.thread.projectId,
390390
...identityOf(first.link),
391391
webUrl:
392-
first.link.repositoryWebUrl ?? (first.link.source === "agent" ? undefined : first.link.url),
392+
first.link.repositoryWebUrl ?? (first.link.source === "agent" ? null : first.link.url),
393393
};
394394
};
395395

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ import * as PullRequestReadCache from "./PullRequestReadCache.ts";
9797
import * as PullRequestProviderRegistry from "./PullRequestProviderRegistry.ts";
9898
import * as ViewedFiles from "./pullRequestViewedFiles.ts";
9999

100-
type WithWebUrl<I> = I & Pick<ProviderRepositoryRef, "webUrl">;
100+
// Null keeps raw API selectors from inheriting an HTTP checkout's URL.
101+
type WithWebUrl<I> = I & { readonly webUrl?: string | null | undefined };
101102
export type PullRequestRef = WithWebUrl<ContractPullRequestRef>;
102103

103104
export interface PullRequestMergeEvent extends PullRequestRef {
@@ -314,7 +315,7 @@ export interface SupportedProject {
314315
readonly api: PullRequestProviderApi;
315316
readonly repository: string;
316317
readonly host: string;
317-
readonly webUrl?: string | undefined;
318+
readonly webUrl?: string | null | undefined;
318319
/**
319320
* Unique where `repository` is not: Azure's is a bare name that repeats across an organisation.
320321
*/
@@ -334,7 +335,7 @@ const providerRef = (project: SupportedProject): ProviderRepositoryRef => ({
334335
cwd: project.project.workspaceRoot,
335336
repository: project.repository,
336337
host: project.host,
337-
...(project.webUrl === undefined ? {} : { webUrl: project.webUrl }),
338+
...(project.webUrl == null ? {} : { webUrl: project.webUrl }),
338339
});
339340

340341
interface WorkspaceProjects {
@@ -804,7 +805,9 @@ export const make = Effect.gen(function* () {
804805
if (host === undefined || host === own.host)
805806
return Effect.succeed({
806807
...own,
807-
...(ref.webUrl === undefined ? {} : { webUrl: withoutUrlCredentials(ref.webUrl) }),
808+
...(ref.webUrl === undefined
809+
? {}
810+
: { webUrl: ref.webUrl === null ? null : withoutUrlCredentials(ref.webUrl) }),
808811
});
809812
}
810813
if (host === undefined) {
@@ -863,7 +866,9 @@ export const make = Effect.gen(function* () {
863866
host,
864867
...(ref.webUrl === undefined
865868
? {}
866-
: { webUrl: withoutUrlCredentials(ref.webUrl) }),
869+
: {
870+
webUrl: ref.webUrl === null ? null : withoutUrlCredentials(ref.webUrl),
871+
}),
867872
remote: normalizeGitRemoteUrl(`https://${host}/${repository}`),
868873
repositoryKey: null,
869874
};
@@ -883,7 +888,9 @@ export const make = Effect.gen(function* () {
883888
? sameRepository
884889
? route.webUrl
885890
: undefined
886-
: withoutUrlCredentials(ref.webUrl),
891+
: ref.webUrl === null
892+
? null
893+
: withoutUrlCredentials(ref.webUrl),
887894
remote: sameRepository
888895
? route.remote
889896
: normalizeGitRemoteUrl(`https://${host}/${repository}`),
@@ -2558,10 +2565,10 @@ export const make = Effect.gen(function* () {
25582565
ref.number,
25592566
ref.expectedAccountId ?? null,
25602567
ref[credentialNamespace] ?? null,
2561-
ref.webUrl ?? null,
2568+
{ webUrl: ref.webUrl },
25622569
]);
25632570
const refOfCacheKey = (key: string): PullRequestRef => {
2564-
const [, projectId, host, repository, number, expectedAccountId, fingerprint, webUrl] =
2571+
const [, projectId, host, repository, number, expectedAccountId, fingerprint, urlReference] =
25652572
JSON.parse(key) as [
25662573
number,
25672574
string,
@@ -2570,14 +2577,14 @@ export const make = Effect.gen(function* () {
25702577
number,
25712578
string | null,
25722579
string | null,
2573-
string | null,
2580+
Pick<PullRequestRef, "webUrl">,
25742581
];
25752582
return {
25762583
projectId,
25772584
...(host === null ? {} : { host }),
25782585
...(expectedAccountId === null ? {} : { expectedAccountId }),
25792586
...(fingerprint === null ? {} : { [credentialNamespace]: fingerprint }),
2580-
...(webUrl === null ? {} : { webUrl }),
2587+
...urlReference,
25812588
repository,
25822589
number,
25832590
} as PullRequestRef;

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as Semaphore from "effect/Semaphore";
66
import {
77
PullRequestOperationError,
88
type PullRequestFilesViewedResult,
9-
type PullRequestRef,
109
type PullRequestSetFilesViewedInput,
1110
} from "@t3tools/contracts";
1211

@@ -15,7 +14,7 @@ import type {
1514
ProviderFileRevisions,
1615
PullRequestProviderError,
1716
} from "@t3tools/source-control-core/server/PullRequestProvider";
18-
import type { PullRequestError, SupportedProject } from "./PullRequestService.ts";
17+
import type { PullRequestError, PullRequestRef, SupportedProject } from "./PullRequestService.ts";
1918

2019
const FILE_REVISIONS_CACHE_TTL = Duration.seconds(60);
2120
const FILE_REVISIONS_STALE_WINDOW = Duration.minutes(10);
@@ -133,7 +132,7 @@ const makeFileRevisions = (dependencies: FileRevisionsDependencies) => {
133132
cwd: project.project.workspaceRoot,
134133
repository: project.repository,
135134
host: project.host,
136-
...(project.webUrl === undefined ? {} : { webUrl: project.webUrl }),
135+
...(project.webUrl == null ? {} : { webUrl: project.webUrl }),
137136
number: ref.number,
138137
paths,
139138
}).pipe(
@@ -317,7 +316,7 @@ export const make = (dependencies: Dependencies) => {
317316
cwd: project.project.workspaceRoot,
318317
repository: project.repository,
319318
host: project.host,
320-
...(project.webUrl === undefined ? {} : { webUrl: project.webUrl }),
319+
...(project.webUrl == null ? {} : { webUrl: project.webUrl }),
321320
number: input.number,
322321
}).pipe(Effect.mapError(toPullRequestError("filesViewed")));
323322
}
@@ -344,7 +343,7 @@ export const make = (dependencies: Dependencies) => {
344343
cwd: project.project.workspaceRoot,
345344
repository: project.repository,
346345
host: project.host,
347-
...(project.webUrl === undefined ? {} : { webUrl: project.webUrl }),
346+
...(project.webUrl == null ? {} : { webUrl: project.webUrl }),
348347
number: input.number,
349348
files: input.files,
350349
}).pipe(Effect.mapError(toPullRequestError("setFilesViewed")));

0 commit comments

Comments
 (0)