Skip to content

Commit

Permalink
Add static constructor for GitRemote.Service from any previously us…
Browse files Browse the repository at this point in the history
…ed name formats (#4469)
  • Loading branch information
pstreef authored Sep 4, 2024
1 parent 25f442f commit 1cf7a3a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
19 changes: 18 additions & 1 deletion rewrite-core/src/main/java/org/openrewrite/GitRemote.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,24 @@ public enum Service {
Bitbucket,
BitbucketCloud,
AzureDevOps,
Unknown
Unknown;

public static Service forName(String serviceName) {
switch (serviceName.toLowerCase(Locale.ENGLISH).replaceAll("[-_ ]", "")) {
case "github":
return GitHub;
case "gitlab":
return GitLab;
case "bitbucket":
return Bitbucket;
case "bitbucketcloud":
return BitbucketCloud;
case "azuredevops":
return AzureDevOps;
default:
return Unknown;
}
}
}

public static class Parser {
Expand Down
17 changes: 17 additions & 0 deletions rewrite-core/src/test/java/org/openrewrite/GitRemoteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,21 @@ void parseOriginCaseInsensitive(String cloneUrl, String expectedOrigin, String e
assertThat(remote.getOrganization()).isEqualTo(expectedOrganization);
assertThat(remote.getRepositoryName()).isEqualTo(expectedRepositoryName);
}

@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){
assertThat(GitRemote.Service.forName(name)).isEqualTo(service);
}
}

0 comments on commit 1cf7a3a

Please sign in to comment.