fix: Support Azure DevOps repository urls without project (#490)

Signed-off-by: Anatolii Bazko <abazko@redhat.com>
pull/492/head
Anatolii Bazko 2023-04-04 16:31:00 +03:00 committed by GitHub
parent b24e3c7d95
commit 8dda567e23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 7 deletions

View File

@ -51,7 +51,7 @@ public class AzureDevOpsURLParser {
this.azureDevOpsPattern =
compile(
format(
"^https://(?<organizationCanIgnore>[^@]++)?@?%s/(?<organization>[^/]++)/?(?<project>[^/]++)/_git/"
"^https://(?<organizationCanIgnore>[^@]++)?@?%s/(?<organization>[^/]++)/((?<project>[^/]++)/)?_git/"
+ "(?<repoName>[^?]++)"
+ "([?&]path=(?<path>[^&]++))?"
+ "([?&]version=GT(?<tag>[^&]++))?"
@ -67,17 +67,20 @@ public class AzureDevOpsURLParser {
public AzureDevOpsUrl parse(String url) {
Matcher matcher = azureDevOpsPattern.matcher(url);
if (!matcher.matches()) {
throw new IllegalArgumentException(
format(
"The given url %s is not a valid. It should start with https://<organization>@%s/ or https://%s/",
url, azureDevOpsScmApiEndpointHost, azureDevOpsScmApiEndpointHost));
throw new IllegalArgumentException(format("The given url %s is not a valid.", url));
}
String project = null;
try {
project = matcher.group("project");
} catch (IllegalArgumentException e) {
}
String project = matcher.group("project");
String repoName = matcher.group("repoName");
if (repoName.endsWith(".git")) {
repoName = repoName.substring(0, repoName.length() - 4);
}
String organization = matcher.group("organization");
String branch = matcher.group("branch");
String tag = matcher.group("tag");

View File

@ -149,7 +149,11 @@ public class AzureDevOpsUrl extends DefaultFactoryUrl {
}
private StringJoiner getRepoPathJoiner() {
return new StringJoiner("/").add(hostName).add(organization).add(project);
StringJoiner repoPath = new StringJoiner("/").add(hostName).add(organization);
if (project != null) {
repoPath.add("_git");
}
return repoPath;
}
@Override

View File

@ -133,6 +133,7 @@ public class AzureDevOpsURLParserTest {
null,
"MyTag"
},
{"https://MyOrg@dev.azure.com/MyOrg/_git/MyRepo", "MyOrg", null, "MyRepo", null, null},
};
}