Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/shared/src/sourceControl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 13 additions & 2 deletions packages/shared/src/sourceControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand Down
Loading