Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Jan 16, 2025
1 parent c9ced19 commit fb9d66b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class AzureDevOpsURLParser {
private final Pattern azureSSHDevOpsPattern;
private final String azureSSHDevOpsPatternTemplate =
"^git@ssh\\.%s:v3/(?<organization>.*)/(?<project>.*)/(?<repoName>.*)$";
private final String azureSSHDevOpsServerPatternTemplate =
"^ssh://\\.%s(:d*)?/(?<organization>.*)/(?<project>.*)/_git/(?<repoName>.*)$";
private final String azureDevOpsPatternTemplate =
"^https?://(?<organizationCanIgnore>[^@]++)?@?%s/(?<organization>[^/]++)/((?<project>[^/]++)/)?_git/"
+ "(?<repoName>[^?]++)"
Expand All @@ -71,15 +73,9 @@ public AzureDevOpsURLParser(
this.azureDevOpsScmApiEndpointHost =
trimEnd(azureDevOpsScmApiEndpoint, '/').replaceFirst("https?://", "");
this.azureDevOpsPattern =
compile(
format(
azureDevOpsPatternTemplate,
azureDevOpsScmApiEndpointHost));
compile(format(azureDevOpsPatternTemplate, azureDevOpsScmApiEndpointHost));
this.azureSSHDevOpsPattern =
compile(
format(
azureSSHDevOpsPatternTemplate,
azureDevOpsScmApiEndpointHost));
compile(format(azureSSHDevOpsPatternTemplate, azureDevOpsScmApiEndpointHost));
}

public boolean isValid(@NotNull String url) {
Expand Down Expand Up @@ -128,19 +124,17 @@ private Optional<String> getServerUrl(String repositoryUrl) {
}

private Optional<Matcher> getPatternMatcherByUrl(String url) {
URI uri =
URI.create(
url.matches(format(azureSSHDevOpsPatternTemplate, ".*"))
? "ssh://" + url.replace(":", "/")
: url);
String scheme = uri.getScheme();
String host = uri.getHost();
Matcher matcher =
compile(format(azureDevOpsPatternTemplate, scheme + "://" + host)).matcher(url);
String host = URI.create(url).getHost();
Matcher matcher = compile(format(azureDevOpsPatternTemplate, host)).matcher(url);
if (matcher.matches()) {
return Optional.of(matcher);
} else {
matcher = compile(format(azureSSHDevOpsPatternTemplate, host)).matcher(url);
if (matcher.matches()) {
return Optional.of(matcher);
} else {
matcher = compile(format(azureSSHDevOpsServerPatternTemplate, host)).matcher(url);
}
return matcher.matches() ? Optional.of(matcher) : Optional.empty();
}
}
Expand All @@ -164,7 +158,7 @@ public AzureDevOpsUrl parse(String url) {
if (!matcher.matches()) {
throw buildIllegalArgumentException(url);
}

String serverUrl = getServerUrl(url).orElseThrow(() -> buildIllegalArgumentException(url));
String repoName = matcher.group("repoName");
String project = matcher.group("project");
if (project == null) {
Expand Down Expand Up @@ -203,6 +197,7 @@ public AzureDevOpsUrl parse(String url) {
.withBranch(branch)
.withTag(tag)
.withDevfileFilenames(devfileFilenamesProvider.getConfiguredDevfileFilenames())
.withServerUrl(serverUrl)
.withUrl(newUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class AzureDevOpsUrl extends DefaultFactoryUrl {

private String tag;

private String serverUrl;

private final List<String> devfileFilenames = new ArrayList<>();

protected AzureDevOpsUrl() {}
Expand Down Expand Up @@ -100,14 +102,19 @@ public AzureDevOpsUrl withBranch(String branch) {

@Override
public String getProviderUrl() {
return "https://" + hostName;
return isNullOrEmpty(serverUrl) ? "https://" + hostName : serverUrl;
}

protected AzureDevOpsUrl withDevfileFilenames(List<String> devfileFilenames) {
this.devfileFilenames.addAll(devfileFilenames);
return this;
}

public AzureDevOpsUrl withServerUrl(String serverUrl) {
this.serverUrl = serverUrl;
return this;
}

@Override
public void setDevfileFilename(String devfileName) {
this.devfileFilenames.clear();
Expand Down

0 comments on commit fb9d66b

Please sign in to comment.