fix: Support Azure DevOps repository urls without project (#490)
Signed-off-by: Anatolii Bazko <abazko@redhat.com>pull/492/head
parent
b24e3c7d95
commit
8dda567e23
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ public class AzureDevOpsURLParserTest {
|
|||
null,
|
||||
"MyTag"
|
||||
},
|
||||
{"https://MyOrg@dev.azure.com/MyOrg/_git/MyRepo", "MyOrg", null, "MyRepo", null, null},
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue