Skip to content

Commit 771f9d4

Browse files
refactor(source-control): PullRequestService reads Azure DevOps addressing, not its kind
PullRequestService checked `kind === "azure-devops"` in eight places: the list cursor key, the routing remote, which checkout serves a hosted reference, and the repository a completed action reports. All eight encode one fact: Azure DevOps addresses a repository by the checkout's full canonical key (`host/org/project/repo`), and derives its organization from that checkout. That fact is now `addressesRepositoriesByCanonicalKey`, an optional PullRequestProviderApi capability the Azure DevOps provider sets. The rate-limit wrapper passes it through, and the test fakes declare it for Azure DevOps, as the real provider does. Behavior is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 18f1ff0 commit 771f9d4

4 files changed

Lines changed: 24 additions & 14 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,9 @@ function fakeProvider(
463463
setReaction: () => Effect.void,
464464
listReviewerCandidates: () => Effect.succeed({ candidates: [], truncated: false }),
465465
setReviewerRequest: () => Effect.void,
466-
// GitHub's own capability, which the service reads instead of the kind.
466+
// The hosts' own capabilities, which the service reads instead of the kind.
467467
...(kind === "github" ? { removesAgentCreditsOnMerge: true } : {}),
468+
...(kind === "azure-devops" ? { addressesRepositoriesByCanonicalKey: true } : {}),
468469
...overrides,
469470
};
470471
}

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ function withRateLimitBackoff(
589589
...(api.removesAgentCreditsOnMerge === undefined
590590
? {}
591591
: { removesAgentCreditsOnMerge: api.removesAgentCreditsOnMerge }),
592+
...(api.addressesRepositoriesByCanonicalKey === undefined
593+
? {}
594+
: { addressesRepositoriesByCanonicalKey: api.addressesRepositoriesByCanonicalKey }),
592595
// Refused during a pause like any other read, except for the caller that asks for the
593596
// bypass: a lookup that failed is not held, so letting every background read through would
594597
// spawn this host's CLI on each of them and re-extend the pause it was already in.
@@ -852,10 +855,8 @@ export const make = Effect.gen(function* () {
852855
if (roots === undefined) viewerRoots.set(host, [project.workspaceRoot]);
853856
else if (!roots.includes(project.workspaceRoot)) roots.push(project.workspaceRoot);
854857
}
855-
const key = listCursorKey(
856-
host,
857-
kind === "azure-devops" ? identity.canonicalKey : repository,
858-
);
858+
const byCanonicalKey = api?.addressesRepositoriesByCanonicalKey === true;
859+
const key = listCursorKey(host, byCanonicalKey ? identity.canonicalKey : repository);
859860
if (seen.has(key)) continue;
860861
seen.add(key);
861862
if (api === null) {
@@ -870,10 +871,9 @@ export const make = Effect.gen(function* () {
870871
api: withRateLimitBackoff(api, host, rateLimits),
871872
repository,
872873
host,
873-
remote:
874-
kind === "azure-devops"
875-
? identity.canonicalKey
876-
: normalizeGitRemoteUrl(`https://${host}/${repository}`),
874+
remote: byCanonicalKey
875+
? identity.canonicalKey
876+
: normalizeGitRemoteUrl(`https://${host}/${repository}`),
877877
});
878878
}
879879
return { supported, unimplemented, viewerRoots };
@@ -922,25 +922,27 @@ export const make = Effect.gen(function* () {
922922
const route =
923923
supported.find(
924924
(candidate) =>
925-
candidate.api.kind === "azure-devops" &&
925+
candidate.api.addressesRepositoriesByCanonicalKey === true &&
926926
candidate.project.repositoryIdentity != null &&
927927
canonicalRepositoryKey(
928928
candidate.project.repositoryIdentity.canonicalKey.toLowerCase(),
929929
) === repositoryKey,
930930
) ??
931931
onHost.find(
932932
(candidate) =>
933-
candidate.api.kind !== "azure-devops" &&
933+
candidate.api.addressesRepositoriesByCanonicalKey !== true &&
934934
candidate.repository.toLowerCase() === repository.toLowerCase(),
935935
) ??
936-
onHost.find((candidate) => candidate.api.kind !== "azure-devops");
936+
onHost.find(
937+
(candidate) => candidate.api.addressesRepositoriesByCanonicalKey !== true,
938+
);
937939
if (route === undefined) {
938940
return Effect.fail(
939941
new PullRequestUnavailableError({ reason: "provider-unsupported" }),
940942
);
941943
}
942944
return Effect.succeed(
943-
route.api.kind === "azure-devops" ||
945+
route.api.addressesRepositoriesByCanonicalKey === true ||
944946
route.repository.toLowerCase() === repository.toLowerCase()
945947
? route
946948
: {
@@ -2099,7 +2101,7 @@ export const make = Effect.gen(function* () {
20992101
),
21002102
Effect.mapError(toPullRequestError("runAction")),
21012103
Effect.as(
2102-
project.api.kind === "azure-devops"
2104+
project.api.addressesRepositoriesByCanonicalKey === true
21032105
? input.repository.trim()
21042106
: project.repository,
21052107
),

‎packages/source-control-azure-devops/src/server/AzureDevOpsPullRequestProvider.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ export const make = Effect.gen(function* () {
298298
const provider: PullRequestProviderApi = {
299299
kind: "azure-devops",
300300
capabilities: CAPABILITIES,
301+
addressesRepositoriesByCanonicalKey: true,
301302

302303
getViewer: (input) =>
303304
cli.getViewer({ cwd: input.cwd }).pipe(Effect.mapError(fail("getViewer"))),

‎packages/source-control-core/src/server/PullRequestProvider.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,12 @@ export interface PullRequestProviderApi {
350350
* it. Server-side only: clients see the effect, not the switch.
351351
*/
352352
readonly removesAgentCreditsOnMerge?: boolean;
353+
/**
354+
* Whether repositories are addressed by the checkout's full canonical key (`host/org/project/
355+
* repo`) rather than `owner/name`. Such a host derives its organization from the checkout, so a
356+
* change request is only served by a checkout of that exact repository.
357+
*/
358+
readonly addressesRepositoriesByCanonicalKey?: boolean;
353359

354360
/** The signed-in account, which is what involvement filtering compares against. */
355361
readonly getViewer: (input: {

0 commit comments

Comments
 (0)