@devries-cameron20 / t3code-1 / commits / bb7ed7381a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(bitbucket): honor the repository in pull request URLs (#25052)

Co-authored-by: Aditya Garud <153842990+yashranaway@users.noreply.github.com>

maria committed Oct 30, 2026 at 21:10 UTC bb7ed7381a03a97dea06b763f73e75f59f039bcf
4 files changed +154 -13
packages/source-control-bitbucket/src/server/BitbucketApi.test.ts
+108
@@ -185,6 +185,114 @@ it.effect("parses pull request responses from the Bitbucket REST API", () => {
185 }).pipe(Effect.provide(layer));
186 });
187
188 +it.effect.each([false, true])("honors PR URL repositories, context=%s", (withContext) => {
189 + const { execute, git, layer } = makeLayer({
190 + response: (request) =>
191 + Response.json(
192 + request.url.endsWith("/pullrequests/42")
193 + ? {
194 + ...bitbucketPullRequest,
195 + source: {
196 + branch: { name: "feature/source-control" },
197 + repository: { full_name: "another/app" },
198 + },
199 + destination: { branch: { name: "main" }, repository: { full_name: "another/app" } },
200 + }
201 + : {
202 + ...repositoryJson,
203 + full_name: "another/app",
204 + links: { clone: [{ name: "ssh", href: "git@bitbucket.org:another/app.git" }] },
205 + },
206 + ),
207 + });
208 + return Effect.gen(function* () {
209 + const bitbucket = yield* BitbucketApi.BitbucketApi;
210 + const input = {
211 + cwd: "/repo",
212 + reference: "https://bitbucket.org/another/app/pull-requests/42",
213 + ...(withContext
214 + ? {
215 + context: {
216 + provider: {
217 + kind: SourceControlProviderKind.make("bitbucket"),
218 + name: "Bitbucket",
219 + baseUrl: "https://bitbucket.org",
220 + },
221 + remoteName: "origin",
222 + remoteUrl: "git@bitbucket.org:pingdotgg/t3code.git",
223 + },
224 + }
225 + : {}),
226 + };
227 + yield* bitbucket.getPullRequest(input);
228 + yield* bitbucket.checkoutPullRequest(input);
229 + assert.deepStrictEqual(
230 + execute.mock.calls.slice(0, 2).map(([request]) => request.url),
231 + [
232 + "https://api.test.local/2.0/repositories/another/app/pullrequests/42",
233 + "https://api.test.local/2.0/repositories/another/app/pullrequests/42",
234 + ],
235 + );
236 + assert.deepStrictEqual(git.ensureRemote.mock.calls[0]?.[0], {
237 + cwd: "/repo",
238 + preferredName: "another",
239 + url: "git@bitbucket.org:another/app.git",
240 + });
241 + assert.deepStrictEqual(git.fetchRemoteBranch.mock.calls[0]?.[0], {
242 + cwd: "/repo",
243 + remoteName: "octocat",
244 + remoteBranch: "feature/source-control",
245 + localBranch: "feature/source-control",
246 + });
247 + assert.deepStrictEqual(git.setBranchUpstream.mock.calls[0]?.[0], {
248 + cwd: "/repo",
249 + branch: "feature/source-control",
250 + remoteName: "octocat",
251 + remoteBranch: "feature/source-control",
252 + });
253 + }).pipe(Effect.provide(layer));
254 +});
255 +
256 +it.effect.each([false, true])(
257 + "reuses matching checkout remotes for numeric references, context=%s",
258 + (withContext) => {
259 + const { git, layer } = makeLayer({
260 + response: () =>
261 + Response.json({
262 + ...bitbucketPullRequest,
263 + source: { ...bitbucketPullRequest.source, repository: { full_name: "pingdotgg/t3code" } },
264 + }),
265 + });
266 + return Effect.gen(function* () {
267 + const bitbucket = yield* BitbucketApi.BitbucketApi;
268 + yield* bitbucket.checkoutPullRequest({
269 + cwd: "/repo",
270 + reference: "#42",
271 + ...(withContext
272 + ? {
273 + context: {
274 + provider: {
275 + kind: SourceControlProviderKind.make("bitbucket"),
276 + name: "Bitbucket",
277 + baseUrl: "https://bitbucket.org",
278 + },
279 + remoteName: "upstream",
280 + remoteUrl: "git@bitbucket.org:PingDotGG/T3Code.git",
281 + },
282 + }
283 + : {}),
284 + });
285 + assert.strictEqual(git.ensureRemote.mock.calls.length, 0);
286 + assert.deepStrictEqual(git.fetchRemoteBranch.mock.calls[0]?.[0], {
287 + cwd: "/repo",
288 + remoteName: withContext ? "upstream" : "origin",
289 + remoteBranch: "feature/source-control",
290 + localBranch: "feature/source-control",
291 + });
292 + }).pipe(Effect.provide(layer));
293 + },
294 +);
295 +
296 it.effect("lists pull requests with Bitbucket state and source branch query params", () => {
297 const { execute, layer } = makeLayer({
298 response: () =>
packages/source-control-bitbucket/src/server/BitbucketApi.ts
+25 -12
@@ -769,6 +769,7 @@ export const make = Effect.gen(function* () {
769
770 const resolveRepository = Effect.fn("BitbucketApi.resolveRepository")(function* (input: {
771 readonly cwd: string;
772 + readonly reference?: string;
773 readonly context?: SourceControlProvider.SourceControlProviderContext;
774 readonly repository?: string;
775 }) {
@@ -780,6 +781,10 @@ export const make = Effect.gen(function* () {
781 return yield* requireRepositoryLocator(input.repository);
782 }
783
784 + const url = input.reference ? URL.parse(input.reference) : null;
785 + const link = url ? definition.parseChangeRequestUrl(url) : null;
786 + if (link) return yield* requireRepositoryLocator(link.repository);
787 +
788 const fromContext =
789 input.context?.provider.kind === "bitbucket"
790 ? parseBitbucketRemoteUrl(input.context.remoteUrl)
@@ -877,19 +882,27 @@ export const make = Effect.gen(function* () {
882 readonly sourceRepositoryName: string;
883 readonly isCrossRepository: boolean;
884 }) {
880 - if (
881 - input.context?.provider.kind === "bitbucket" &&
882 - !input.isCrossRepository &&
883 - parseBitbucketRemoteUrl(input.context.remoteUrl) !== null
884 - ) {
885 - return input.context.remoteName;
886 - }
887 -
885 if (!input.isCrossRepository) {
889 - const remoteName = yield* git
890 - .resolvePrimaryRemoteName(input.cwd)
891 - .pipe(Effect.orElseSucceed(() => null));
892 - if (remoteName) return remoteName;
886 + const context = input.context?.provider.kind === "bitbucket" ? input.context : undefined;
887 + const remoteName =
888 + context?.remoteName ??
889 + (yield* git.resolvePrimaryRemoteName(input.cwd).pipe(Effect.orElseSucceed(() => null)));
890 + if (remoteName) {
891 + const remoteUrl =
892 + context?.remoteUrl ??
893 + (yield* readConfigValueNullable(input.cwd, `remote.${remoteName}.url`));
894 + const repository =
895 + remoteUrl && (context || recognizeRemoteWith(definition, remoteUrl))
896 + ? parseBitbucketRemoteUrl(remoteUrl)
897 + : null;
898 + if (
899 + repository &&
900 + `${repository.workspace}/${repository.repoSlug}`.toLowerCase() ===
901 + input.sourceRepositoryName.toLowerCase()
902 + ) {
903 + return remoteName;
904 + }
905 + }
906 }
907
908 const cloneUrls = yield* getRepository({
packages/source-control-bitbucket/src/shared/definition.test.ts
+13
@@ -7,6 +7,11 @@ const parse = (url: string) => definition.parseChangeRequestUrl(new URL(url));
7
8 describe("Bitbucket change request URLs", () => {
9 it("reads a pull request on Bitbucket hosts", () => {
10 + expect(
11 + definition.isChangeRequestReference(
12 + "https://bitbucket.org/workspace/repo/pull-requests/5/diff",
13 + ),
14 + ).toBe(true);
15 expect(parse("https://bitbucket.org/workspace/repo/pull-requests/5/diff")).toEqual({
16 host: "bitbucket.org",
17 repository: "workspace/repo",
@@ -21,6 +26,14 @@ describe("Bitbucket change request URLs", () => {
26
27 it("leaves other hosts alone", () => {
28 expect(parse("https://scm.example.test/workspace/repo/pull-requests/5")).toBeNull();
29 + expect(
30 + definition.isChangeRequestReference(
31 + "https://scm.example.test/workspace/repo/pull-requests/5",
32 + ),
33 + ).toBe(false);
34 + expect(
35 + definition.isChangeRequestReference("https://bitbucket.org/workspace/repo/src/main"),
36 + ).toBe(false);
37 });
38
39 it("builds pull request URLs below the repository", () => {
packages/source-control-bitbucket/src/shared/definition.ts
+8 -1
@@ -107,7 +107,14 @@ export const definition = defineSourceControl({
107 authorProfileUrl: () => null,
108 reviewSummaryRequired: () => false,
109 checkoutCommandArgument: () => null,
110 - isChangeRequestReference: () => false,
110 + isChangeRequestReference: (reference) => {
111 + const url = URL.parse(reference);
112 + return (
113 + url !== null &&
114 + isBitbucketHost(url.hostname) &&
115 + parseChangeRequestPath(url, CHANGE_REQUEST_PATH) !== null
116 + );
117 + },
118 checkoutChangeRequestHost: () => null,
119 recognizeRemote: ({ host, hostname }) =>
120 hostname === "bitbucket.org" || hostname.split(".").includes("bitbucket")