Skip to content

Commit 0310f0c

Browse files
fix(server): preserve raw GitLab selectors through checkout routing
1 parent 5764c41 commit 0310f0c

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
@@ -280,6 +280,7 @@ const make = Effect.gen(function* () {
280280
host: target.host,
281281
repository: target.repository,
282282
number: target.number,
283+
webUrl: null,
283284
});
284285
const url = yield* Effect.try(() => new URL(detail.url));
285286
url.username = "";
@@ -305,11 +306,12 @@ const make = Effect.gen(function* () {
305306
if (watching && before?.snapshot?.state === "merged") {
306307
return yield* new PullRequestNotOpenError({ state: "merged" });
307308
}
308-
const link = watching
309-
? yield* resolveLink(target, input, project).pipe(
310-
Effect.mapError((cause) => new PullRequestWatchFailedError({ cause })),
311-
)
312-
: undefined;
309+
const link =
310+
watching && before === undefined
311+
? yield* resolveLink(target, input, project).pipe(
312+
Effect.mapError((cause) => new PullRequestWatchFailedError({ cause })),
313+
)
314+
: undefined;
313315
yield* engine
314316
.dispatch({
315317
type: "thread.pull-request.watch",
@@ -327,7 +329,7 @@ const make = Effect.gen(function* () {
327329
host: target.host,
328330
repository: target.repository,
329331
number: target.number,
330-
url: link?.url ?? target.url,
332+
url: link?.url ?? before?.url ?? target.url,
331333
watching: watchedLink(after)?.watch !== undefined,
332334
wasWatching: before?.watch !== undefined,
333335
};

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ export const make = Effect.gen(function* () {
286286
repository: first.link.repository,
287287
number: first.link.number,
288288
webUrl:
289-
first.link.repositoryWebUrl ??
290-
(first.link.source === "agent" ? undefined : first.link.url),
289+
first.link.repositoryWebUrl ?? (first.link.source === "agent" ? null : first.link.url),
291290
};
292291
const refreshRequested = requested.has(key);
293292
// 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}`),
@@ -2562,10 +2569,10 @@ export const make = Effect.gen(function* () {
25622569
ref.number,
25632570
ref.expectedAccountId ?? null,
25642571
ref[credentialNamespace] ?? null,
2565-
ref.webUrl ?? null,
2572+
{ webUrl: ref.webUrl },
25662573
]);
25672574
const refOfCacheKey = (key: string): PullRequestRef => {
2568-
const [, projectId, host, repository, number, expectedAccountId, fingerprint, webUrl] =
2575+
const [, projectId, host, repository, number, expectedAccountId, fingerprint, urlReference] =
25692576
JSON.parse(key) as [
25702577
number,
25712578
string,
@@ -2574,14 +2581,14 @@ export const make = Effect.gen(function* () {
25742581
number,
25752582
string | null,
25762583
string | null,
2577-
string | null,
2584+
Pick<PullRequestRef, "webUrl">,
25782585
];
25792586
return {
25802587
projectId,
25812588
...(host === null ? {} : { host }),
25822589
...(expectedAccountId === null ? {} : { expectedAccountId }),
25832590
...(fingerprint === null ? {} : { [credentialNamespace]: fingerprint }),
2584-
...(webUrl === null ? {} : { webUrl }),
2591+
...urlReference,
25852592
repository,
25862593
number,
25872594
} 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)