azureCloneUrl function
The clone url of the Azure DevOps repository parsed names, rebuilt from
its parts in the form Azure serves:
https://dev.azure.com/<org>/<project>/_git/<repo> or, on the legacy host,
https://<org>.visualstudio.com/<project>/_git/<repo>.
Azure rejects a .git suffix here — it reads repo.git as a repository,
or in the <org>/_git/<repo> shortcut as a project, that does not exist.
Rebuilding drops a suffix the user typed, and turns the shortcut into the
unambiguous full form. Returns null when parsed lacks a part.
Implementation
String? azureCloneUrl(Uri uri, ParseResult parsed) {
final org = parsed.org;
final project = parsed.project;
final repo = parsed.repo;
if (org == null || project == null || repo == null) {
return null;
}
final isLegacyHost = uri.host.toLowerCase().endsWith('.visualstudio.com');
return Uri(
scheme: uri.scheme,
userInfo: uri.userInfo,
host: uri.host,
pathSegments: [if (!isLegacyHost) org, project, '_git', repo],
).toString();
}