Skip to content

Commit 3180dd3

Browse files
committed
fix(azure-devops): preserve ref prefixes when encoding branches
1 parent 638f2f1 commit 3180dd3

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ describe("AzureDevOpsCli.layer", () => {
233233
}).pipe(Effect.provide(layer)),
234234
);
235235

236-
it.effect("percent-encodes the source branch so `#` is not read as a URL fragment", () =>
236+
it.effect("percent-encodes the source branch while preserving recognized ref prefixes", () =>
237237
Effect.gen(function* () {
238238
mockRun.mockReturnValueOnce(Effect.succeed(processOutput("[]")));
239239

@@ -246,6 +246,22 @@ describe("AzureDevOpsCli.layer", () => {
246246

247247
const args = mockRun.mock.calls.at(-1)?.[0].args ?? [];
248248
assert.strictEqual(args[args.indexOf("--source-branch") + 1], "user%2Ffeat%2F1-(%232)-slug");
249+
250+
for (const prefix of ["refs/heads/", "refs/pull/", "refs/tags/"]) {
251+
mockRun.mockReturnValueOnce(Effect.succeed(processOutput("[]")));
252+
yield* az.listPullRequests({
253+
cwd: "/somewhere",
254+
headSelector: "fallback",
255+
source: { refName: `${prefix}user/feat/1-(#2)-slug` },
256+
state: "open",
257+
});
258+
259+
const refArgs = mockRun.mock.calls.at(-1)?.[0].args ?? [];
260+
assert.strictEqual(
261+
refArgs[refArgs.indexOf("--source-branch") + 1],
262+
`${prefix}user%2Ffeat%2F1-(%232)-slug`,
263+
);
264+
}
249265
}).pipe(Effect.provide(layer)),
250266
);
251267

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ export const make = Effect.gen(function* () {
401401
return AzureDevOpsCli.of({
402402
execute,
403403
listPullRequests: Effect.fn("AzureDevOpsCli.listPullRequests")(function (input) {
404+
const branch = SourceControlProvider.sourceBranch(input);
405+
// az checks literal ref prefixes before constructing the request URL.
406+
const refPrefix =
407+
["refs/heads/", "refs/pull/", "refs/tags/"].find((prefix) => branch.startsWith(prefix)) ??
408+
"";
404409
return executeJson({
405410
cwd: input.cwd,
406411
args: [
@@ -411,7 +416,7 @@ export const make = Effect.gen(function* () {
411416
"true",
412417
"--source-branch",
413418
// az puts this in the query string unescaped; a `#` would cut the request.
414-
encodeURIComponent(SourceControlProvider.sourceBranch(input)),
419+
refPrefix + encodeURIComponent(branch.slice(refPrefix.length)),
415420
"--status",
416421
toAzureStatus(input.state),
417422
"--top",

0 commit comments

Comments
 (0)