Skip to content

Commit

Permalink
Strip off : from organizationName with baseUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Feb 23, 2024
1 parent 711eee3 commit d3f99a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.util.*;

import static java.util.Collections.emptyList;
Expand Down Expand Up @@ -88,10 +87,12 @@ public String getOrganizationName(String baseUrl) {
baseUrl = baseUrl.substring(4);
}
String remainder = origin.substring(origin.indexOf(baseUrl) + baseUrl.length());
if (remainder.startsWith(":")) {
remainder = remainder.substring(1);
}
if (remainder.startsWith("/")) {
remainder = remainder.substring(1);
}

return remainder.substring(0, remainder.lastIndexOf('/'));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.openrewrite.marker.ci.*;

Expand Down Expand Up @@ -70,6 +71,16 @@ void getOrganizationName(String remote) {
.isEqualTo("openrewrite");
}

@ParameterizedTest
@CsvSource({
"[email protected]:organization/subgroup/repository.git, https://gitlab.acme.com, organization/subgroup",
"[email protected]:organization/subgroup/repository.git, [email protected], organization/subgroup"
})
void getOrganizationNameWithBaseUrl(String gitOrigin, String baseUrl, String organizationName) {
assertThat(new GitProvenance(randomId(), gitOrigin, "main", "123", null, null, emptyList()).getOrganizationName(baseUrl))
.isEqualTo(organizationName);
}

@ParameterizedTest
@MethodSource("remotes")
void getRepositoryName(String remote) {
Expand Down

0 comments on commit d3f99a0

Please sign in to comment.