Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forge: add HostedRepository.nonTransformedWebUrl #546

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -91,6 +91,11 @@ public URI webUrl() {
return webUrl;
}

@Override
public URI nonTransformedWebUrl() {
return webUrl();
}

@Override
public URI webUrl(Hash hash) {
return null;
@@ -56,6 +56,7 @@ PullRequest createPullRequest(HostedRepository target,
Optional<HostedRepository> parent();
URI url();
URI webUrl();
URI nonTransformedWebUrl();
URI webUrl(Hash hash);
VCS repositoryType();
String fileContents(String filename, String ref);
@@ -137,11 +137,15 @@ public URI getURI() {
}

URI getWebURI(String endpoint) {
return getWebURI(endpoint, true);
}

URI getWebURI(String endpoint, boolean transform) {
var baseWebUri = URIBuilder.base(uri)
.setPath(endpoint)
.build();

if (webUriPattern == null) {
if (webUriPattern == null || !transform) {
return baseWebUri;
}

@@ -188,6 +188,12 @@ public URI webUrl() {
return gitHubHost.getWebURI(endpoint);
}

@Override
public URI nonTransformedWebUrl() {
var endpoint = "/" + repository;
return gitHubHost.getWebURI(endpoint, false);
}

@Override
public URI webUrl(Hash hash) {
var endpoint = "/" + repository + "/commit/" + hash.abbreviate();
@@ -159,6 +159,11 @@ public URI webUrl() {
.build();
}

@Override
public URI nonTransformedWebUrl() {
return webUrl();
}

@Override
public URI webUrl(Hash hash) {
return URIBuilder.base(gitLabHost.getUri())
@@ -41,4 +41,14 @@ void webUriPatternReplacement() throws IOException, URISyntaxException {
assertEquals(new URI("http://www.example.com/another/hello"), host.getWebURI("/test/hello"));
}
}

@Test
void nonTransformedWebUrl() throws IOException, URISyntaxException {
try (var tempFolder = new TemporaryDirectory()) {
var host = new GitHubHost(URIBuilder.base("http://www.example.com").build(),
Pattern.compile("^(http://www.example.com)/test/(.*)$"), "$1/another/$2");
assertEquals(new URI("http://www.example.com/another/hello"), host.getWebURI("/test/hello"));
assertEquals(new URI("http://www.example.com/test/hello"), host.getWebURI("/test/hello", false));
}
}
}
@@ -126,6 +126,11 @@ public URI webUrl() {
return url();
}

@Override
public URI nonTransformedWebUrl() {
return url();
}

@Override
public URI webUrl(Hash hash) {
try {