Skip to content
TypeScript

fix(shared): Azure DevOps repositories with a space in the name list their pull requests (#22782)

Pavel Kroupa855db968a751
diff --git a/packages/shared/src/sourceControl.test.ts b/packages/shared/src/sourceControl.test.ts
index cb45f8c39fb..23d0c8b4ba8 100644
--- a/packages/shared/src/sourceControl.test.ts
+++ b/packages/shared/src/sourceControl.test.ts
@@ -149,6 +149,17 @@ it("names an Azure DevOps repository by its own name, not its project path", ()
expect(selector).toBe("checkout");
});
+it("decodes an Azure DevOps repository name that the remote URL percent-encodes", () => {
+ // A remote spells a space as `%20`, and `az repos pr list --repository` reads that literally.
+ const selector = sourceControlRepositorySelector({
+ provider: "azure-devops",
+ displayName: "contoso/payments%20(eu)/_git/checkout%20(eu)",
+ owner: "contoso",
+ name: "checkout%20(eu)",
+ });
+ expect(selector).toBe("checkout (eu)");
+});
+
it("keeps a GitLab identity's whole path, because a nested group is part of the name", () => {
const selector = sourceControlRepositorySelector({
provider: "gitlab",
diff --git a/packages/shared/src/sourceControl.ts b/packages/shared/src/sourceControl.ts
index a56d10eb896..5729d201501 100644
--- a/packages/shared/src/sourceControl.ts
+++ b/packages/shared/src/sourceControl.ts
@@ -278,11 +278,21 @@ export function detectSourceControlProviderFromRemoteUrl(
};
}
+function decodeUrlPathSegment(segment: string): string {
+ try {
+ return decodeURIComponent(segment);
+ } catch {
+ return segment;
+ }
+}
+
/**
* Azure DevOps is the exception: `az repos pr list --repository` takes a repository name, and
* takes the organisation and project from the checkout it detects — so the recorded
* `org/project/_git/repo` path is refused outright and the whole repository reads as
- * unavailable. Its name is the last segment, which is what this hands over.
+ * unavailable. Its name is the last segment, which is what this hands over. The segment comes
+ * from the remote URL, where a name with a space reads `my%20repo`; `az` looks that up literally
+ * and answers 404, so it goes out decoded.
*/
export function sourceControlRepositorySelector(
identity:
@@ -293,7 +303,8 @@ export function sourceControlRepositorySelector(
if (!identity) return null;
if (identity.provider === "azure-devops") {
const segments = (identity.displayName ?? "").split("/").filter((part) => part !== "_git");
- return identity.name || segments.at(-1) || null;
+ const name = identity.name || segments.at(-1);
+ return name ? decodeUrlPathSegment(name) : null;
}
if (identity.displayName) return identity.displayName;
return identity.owner && identity.name ? `${identity.owner}/${identity.name}` : null;