Skip to content

Commit

Permalink
Merge branch 'main' into fix-groovy-multivariable-declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
jevanlingen authored Dec 11, 2024
2 parents 422df9e + ecfb0e5 commit 0a92ffe
Show file tree
Hide file tree
Showing 10 changed files with 828 additions and 46 deletions.
30 changes: 17 additions & 13 deletions rewrite-core/src/main/java/org/openrewrite/GitRemote.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,51 +113,55 @@ public Parser() {
* @return the clone url
*/
public URI toUri(GitRemote remote, String protocol) {
return buildUri(remote.service, remote.origin, remote.path, protocol);
}

public URI buildUri(Service service, String origin, String path, String protocol) {
if (!ALLOWED_PROTOCOLS.contains(protocol)) {
throw new IllegalArgumentException("Invalid protocol: " + protocol + ". Must be one of: " + ALLOWED_PROTOCOLS);
}
URI selectedBaseUrl;

if (remote.service == Service.Unknown) {
if (PORT_PATTERN.matcher(remote.origin).find()) {
throw new IllegalArgumentException("Unable to determine protocol/port combination for an unregistered origin with a port: " + remote.origin);
if (service == Service.Unknown) {
if (PORT_PATTERN.matcher(origin).find()) {
throw new IllegalArgumentException("Unable to determine protocol/port combination for an unregistered origin with a port: " + origin);
}
selectedBaseUrl = URI.create(protocol + "://" + stripProtocol(remote.origin));
selectedBaseUrl = URI.create(protocol + "://" + stripProtocol(origin));
} else {
selectedBaseUrl = servers.stream()
.filter(server -> server.allOrigins()
.stream()
.anyMatch(origin -> origin.equalsIgnoreCase(stripProtocol(remote.origin)))
.anyMatch(o -> o.equalsIgnoreCase(stripProtocol(origin)))
)
.flatMap(server -> server.getUris().stream())
.filter(uri -> uri.getScheme().equals(protocol))
.findFirst()
.orElseGet(() -> {
URI normalizedUri = Parser.normalize(remote.origin);
URI normalizedUri = Parser.normalize(origin);
if (!normalizedUri.getScheme().equals(protocol)) {
throw new IllegalStateException("No matching server found that supports ssh for origin: " + remote.origin);
throw new IllegalStateException("No matching server found that supports ssh for origin: " + origin);
}
return normalizedUri;
});
}

String path = remote.path.replaceFirst("^/", "");
path = path.replaceFirst("^/", "");
boolean ssh = protocol.equals("ssh");
switch (remote.service) {
switch (service) {
case Bitbucket:
if (!ssh) {
path = "scm/" + remote.path;
path = "scm/" + path;
}
break;
case AzureDevOps:
if (ssh) {
path = "v3/" + remote.path;
path = "v3/" + path;
} else {
path = remote.path.replaceFirst("([^/]+)/([^/]+)/(.*)", "$1/$2/_git/$3");
path = path.replaceFirst("([^/]+)/([^/]+)/(.*)", "$1/$2/_git/$3");
}
break;
}
if (remote.service != Service.AzureDevOps) {
if (service != Service.AzureDevOps) {
path += ".git";
}
String maybeSlash = selectedBaseUrl.toString().endsWith("/") ? "" : "/";
Expand Down
24 changes: 12 additions & 12 deletions rewrite-core/src/test/java/org/openrewrite/GitRemoteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,18 @@ void parseOriginCaseInsensitive(String cloneUrl, String expectedOrigin, String e

@ParameterizedTest
@CsvSource(textBlock = """
GitHub, GitHub
GITLAB, GitLab
bitbucket, Bitbucket
BitbucketCloud, BitbucketCloud
Bitbucket Cloud, BitbucketCloud
BITBUCKET_CLOUD, BitbucketCloud
AzureDevOps, AzureDevOps
AZURE_DEVOPS, AzureDevOps
Azure DevOps, AzureDevOps
idontknow, Unknown
""")
void findServiceForName(String name, GitRemote.Service service){
GitHub, GitHub
GITLAB, GitLab
bitbucket, Bitbucket
BitbucketCloud, BitbucketCloud
Bitbucket Cloud, BitbucketCloud
BITBUCKET_CLOUD, BitbucketCloud
AzureDevOps, AzureDevOps
AZURE_DEVOPS, AzureDevOps
Azure DevOps, AzureDevOps
idontknow, Unknown
""")
void findServiceForName(String name, GitRemote.Service service) {
assertThat(GitRemote.Service.forName(name)).isEqualTo(service);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
G.MapEntry mapEntry = null;
String classifierStringDelimiter = null;
int index = 0;
for (Expression e : depArgs) {
if (!(e instanceof G.MapEntry)) {
continue;
}
G.MapEntry arg = (G.MapEntry) e;
for (G.MapEntry arg : map.getElements()) {
if (!(arg.getKey() instanceof J.Literal) || !(arg.getValue() instanceof J.Literal)) {
continue;
}
Expand Down
Loading

0 comments on commit 0a92ffe

Please sign in to comment.