mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-05 20:28:28 +02:00
Add http protocol link to repository object response
This commit is contained in:
@@ -60,7 +60,6 @@ import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static sonia.scm.it.RegExMatcher.matchesPattern;
|
||||
import static sonia.scm.it.RestUtil.BASE_URL;
|
||||
import static sonia.scm.it.RestUtil.createResourceUrl;
|
||||
import static sonia.scm.it.RestUtil.given;
|
||||
|
||||
@@ -195,7 +194,19 @@ public class RepositoriesITCase {
|
||||
|
||||
private RepositoryClient createRepositoryClient() throws IOException {
|
||||
RepositoryClientFactory clientFactory = new RepositoryClientFactory();
|
||||
return clientFactory.create(repositoryType, BASE_URL + repositoryType + "/scmadmin/HeartOfGold-" + repositoryType, "scmadmin", "scmadmin", temporaryFolder.newFolder());
|
||||
String cloneUrl = readCloneUrl();
|
||||
return clientFactory.create(repositoryType, cloneUrl, "scmadmin", "scmadmin", temporaryFolder.newFolder());
|
||||
}
|
||||
|
||||
private String readCloneUrl() {
|
||||
return given(VndMediaType.REPOSITORY)
|
||||
|
||||
.when()
|
||||
.get(repositoryUrl)
|
||||
|
||||
.then()
|
||||
.extract()
|
||||
.path("_links.httpProtocol.href");
|
||||
}
|
||||
|
||||
private String repositoryJson() {
|
||||
|
||||
@@ -25,6 +25,7 @@ public abstract class RepositoryToRepositoryDtoMapper extends BaseMapper<Reposit
|
||||
@AfterMapping
|
||||
void appendLinks(Repository repository, @MappingTarget RepositoryDto target) {
|
||||
Links.Builder linksBuilder = linkingTo().self(resourceLinks.repository().self(target.getNamespace(), target.getName()));
|
||||
linksBuilder.single(link("httpProtocol", resourceLinks.repository().clone(target.getType(), target.getNamespace(), target.getName())));
|
||||
if (RepositoryPermissions.delete(repository).isPermitted()) {
|
||||
linksBuilder.single(link("delete", resourceLinks.repository().delete(target.getNamespace(), target.getName())));
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package sonia.scm.api.v2.resources;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.net.URI;
|
||||
|
||||
class ResourceLinks {
|
||||
|
||||
@@ -127,15 +128,21 @@ class ResourceLinks {
|
||||
|
||||
static class RepositoryLinks {
|
||||
private final LinkBuilder repositoryLinkBuilder;
|
||||
private final UriInfo uriInfo;
|
||||
|
||||
RepositoryLinks(UriInfo uriInfo) {
|
||||
repositoryLinkBuilder = new LinkBuilder(uriInfo, RepositoryRootResource.class, RepositoryResource.class);
|
||||
this.uriInfo = uriInfo;
|
||||
}
|
||||
|
||||
String self(String namespace, String name) {
|
||||
return repositoryLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("get").parameters().href();
|
||||
}
|
||||
|
||||
String clone(String type, String namespace, String name) {
|
||||
return uriInfo.getBaseUri().resolve(URI.create("../../" + type + "/" + namespace + "/" + name)).toASCIIString();
|
||||
}
|
||||
|
||||
String delete(String namespace, String name) {
|
||||
return repositoryLinkBuilder.method("getRepositoryResource").parameters(namespace, name).method("delete").parameters().href();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user