Sagan's working
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -12,7 +12,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-build</artifactId>
|
||||
<version>1.3.5.BUILD-SNAPSHOT</version>
|
||||
<version>1.3.5.RELEASE</version>
|
||||
<relativePath/>
|
||||
<!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.springframework.cloud.internal</groupId>
|
||||
<artifactId>spring-cloud-release-tools-core</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.springframework.cloud.release.internal.sagan;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class Project {
|
||||
public String id = "";
|
||||
public String name = "";
|
||||
public String repoUrl = "";
|
||||
public String siteUrl = "";
|
||||
public String category = "";
|
||||
public String stackOverflowTags;
|
||||
public List<Release> projectReleases = new ArrayList<>();
|
||||
public List<String> stackOverflowTagList = new ArrayList<>();
|
||||
public boolean aggregator;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package org.springframework.cloud.release.internal.sagan;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
class ProjectMetadata {
|
||||
private String id = "";
|
||||
private String name = "";
|
||||
private String repoUrl = "";
|
||||
private String siteUrl = "";
|
||||
private String category = "";
|
||||
private String stackOverflowTags;
|
||||
private boolean aggregator;
|
||||
private List<String> stackOverflowTagList;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.springframework.cloud.release.internal.sagan;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class Release {
|
||||
public String releaseStatus = "";
|
||||
public String refDocUrl = "";
|
||||
public String apiDocUrl = "";
|
||||
public String groupId = "";
|
||||
public String artifactId = "";
|
||||
public Repository repository;
|
||||
public String version = "";
|
||||
public boolean current;
|
||||
public boolean generalAvailability;
|
||||
public boolean preRelease;
|
||||
public String versionDisplayName = "";
|
||||
public boolean snapshot;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package org.springframework.cloud.release.internal.sagan;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
class ReleaseMetadata {
|
||||
private String releaseStatus;
|
||||
private String refDocUrl;
|
||||
private String apiDocUrl;
|
||||
private String groupId;
|
||||
private String artifactId;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.springframework.cloud.release.internal.sagan;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class ReleaseUpdate {
|
||||
public String groupId = "";
|
||||
public String artifactId = "";
|
||||
public String version = "";
|
||||
public String releaseStatus = "";
|
||||
public String refDocUrl = "";
|
||||
public String apiDocUrl = "";
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.springframework.cloud.release.internal.sagan;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class Repository {
|
||||
public String id;
|
||||
public String name;
|
||||
public String url;
|
||||
public boolean snapshotsEnabled;
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package org.springframework.cloud.release.internal.sagan;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
class RepositoryMetadata {
|
||||
private String id;
|
||||
private String name;
|
||||
private String url;
|
||||
private boolean snapshotsEnabled;
|
||||
|
||||
public RepositoryMetadata() {
|
||||
}
|
||||
|
||||
public RepositoryMetadata(String id, String name, String url,
|
||||
boolean snapshotsEnabled) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.snapshotsEnabled = snapshotsEnabled;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public boolean isSnapshotsEnabled() {
|
||||
return this.snapshotsEnabled;
|
||||
}
|
||||
|
||||
public void setSnapshotsEnabled(boolean snapshotsEnabled) {
|
||||
this.snapshotsEnabled = snapshotsEnabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.springframework.cloud.release.internal.sagan;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.springframework.cloud.release.internal.ReleaserProperties;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.RequestEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
class RestTemplateSaganClient implements SaganClient {
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
private final String baseUrl;
|
||||
|
||||
RestTemplateSaganClient(RestTemplate restTemplate, ReleaserProperties properties) {
|
||||
this.restTemplate = restTemplate;
|
||||
this.baseUrl = properties.getSagan().getBaseUrl();
|
||||
}
|
||||
|
||||
@Override public Project getProject(String projectName) {
|
||||
return this.restTemplate.getForObject(this.baseUrl + "/project_metadata/{projectName}", Project.class, projectName);
|
||||
}
|
||||
|
||||
@Override public Release getRelease(String projectName, String releaseVersion) {
|
||||
return this.restTemplate.getForObject(this.baseUrl + "/project_metadata/{projectName}/releases/{releaseVersion}", Release.class, projectName, releaseVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Release createOrUpdateRelease(String projectName, ReleaseUpdate releaseUpdate) {
|
||||
RequestEntity<ReleaseUpdate> request = RequestEntity
|
||||
.post(URI.create(this.baseUrl +"/project_metadata/" + projectName + "/releases"))
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
.body(releaseUpdate);
|
||||
return this.restTemplate.exchange(request, Release.class).getBody();
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,12 @@
|
||||
package org.springframework.cloud.release.internal.sagan;
|
||||
|
||||
import org.springframework.cloud.release.internal.ReleaserProperties;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
class SaganClient {
|
||||
public interface SaganClient {
|
||||
Project getProject(String projectName);
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
private final String baseUrl;
|
||||
Release getRelease(String projectName, String releaseVersion);
|
||||
|
||||
SaganClient(RestTemplate restTemplate, ReleaserProperties properties) {
|
||||
this.restTemplate = restTemplate;
|
||||
this.baseUrl = properties.getSagan().getBaseUrl();
|
||||
}
|
||||
|
||||
void getProject(String projectName) {
|
||||
this.restTemplate.getForObject(this.baseUrl + "/project_metadata/{projectName}", Object.class, projectName);
|
||||
}
|
||||
|
||||
void getRelease(String projectName, String releaseVersion) {
|
||||
|
||||
}
|
||||
|
||||
// POST
|
||||
void createOrUpdateRelease(String projectName, Object release) {
|
||||
|
||||
}
|
||||
Release createOrUpdateRelease(String projectName, ReleaseUpdate releaseUpdate);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
package org.springframework.cloud.release.internal.sagan;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner;
|
||||
import org.springframework.cloud.release.internal.ReleaserProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = RestTemplateSaganClientTests.Config.class)
|
||||
@AutoConfigureStubRunner(ids = "sagan:sagan-site")
|
||||
public class RestTemplateSaganClientTests {
|
||||
|
||||
@Value("${stubrunner.runningstubs.sagan-site.port}") Integer saganPort;
|
||||
SaganClient client;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
ReleaserProperties properties = new ReleaserProperties();
|
||||
properties.getGit().setOauthToken("foo");
|
||||
properties.getSagan().setBaseUrl("http://localhost:" + saganPort);
|
||||
this.client = saganClient(properties);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_get_a_project() {
|
||||
Project project = this.client.getProject("spring-framework");
|
||||
|
||||
then(project.id).isEqualTo("spring-framework");
|
||||
then(project.name).isEqualTo("Spring Framework");
|
||||
then(project.repoUrl).isEqualTo("http://github.com/spring-projects/spring-framework");
|
||||
then(project.siteUrl).isEqualTo("http://projects.spring.io/spring-framework");
|
||||
then(project.category).isEqualTo("active");
|
||||
then(project.stackOverflowTags).isNotBlank();
|
||||
then(project.stackOverflowTagList).isNotEmpty();
|
||||
then(project.aggregator).isFalse();
|
||||
then(project.projectReleases).isNotEmpty();
|
||||
Release release = project.projectReleases.get(0);
|
||||
then(release.releaseStatus).isEqualTo("PRERELEASE");
|
||||
then(release.refDocUrl).isEqualTo("http://docs.spring.io/spring/docs/5.0.0.RC4/spring-framework-reference/");
|
||||
then(release.apiDocUrl).isEqualTo("http://docs.spring.io/spring/docs/5.0.0.RC4/javadoc-api/");
|
||||
then(release.groupId).isEqualTo("org.springframework");
|
||||
then(release.artifactId).isEqualTo("spring-context");
|
||||
then(release.repository.id).isEqualTo("spring-milestones");
|
||||
then(release.repository.name).isEqualTo("Spring Milestones");
|
||||
then(release.repository.url).isEqualTo("https://repo.spring.io/libs-milestone");
|
||||
then(release.repository.snapshotsEnabled).isFalse();
|
||||
then(release.version).isEqualTo("5.0.0.RC4");
|
||||
then(release.current).isFalse();
|
||||
then(release.generalAvailability).isFalse();
|
||||
then(release.preRelease).isTrue();
|
||||
then(release.versionDisplayName).isEqualTo("5.0.0 RC4");
|
||||
then(release.snapshot).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_get_a_release() {
|
||||
Release release = this.client.getRelease("spring-framework", "5.0.0.RC4");
|
||||
|
||||
then(release.releaseStatus).isEqualTo("PRERELEASE");
|
||||
then(release.refDocUrl).isEqualTo("http://docs.spring.io/spring/docs/{version}/spring-framework-reference/");
|
||||
then(release.apiDocUrl).isEqualTo("http://docs.spring.io/spring/docs/{version}/javadoc-api/");
|
||||
then(release.groupId).isEqualTo("org.springframework");
|
||||
then(release.artifactId).isEqualTo("spring-context");
|
||||
then(release.repository.id).isEqualTo("spring-milestones");
|
||||
then(release.repository.name).isEqualTo("Spring Milestones");
|
||||
then(release.repository.url).isEqualTo("https://repo.spring.io/libs-milestone");
|
||||
then(release.repository.snapshotsEnabled).isFalse();
|
||||
then(release.version).isEqualTo("5.0.0.RC4");
|
||||
then(release.current).isFalse();
|
||||
then(release.generalAvailability).isFalse();
|
||||
then(release.preRelease).isTrue();
|
||||
then(release.versionDisplayName).isEqualTo("5.0.0 RC4");
|
||||
then(release.snapshot).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_update_a_release() {
|
||||
ReleaseUpdate releaseUpdate = new ReleaseUpdate();
|
||||
releaseUpdate.groupId = "org.springframework";
|
||||
releaseUpdate.artifactId = "spring-context";
|
||||
releaseUpdate.version = "1.2.3.RELEASE";
|
||||
releaseUpdate.releaseStatus = "GENERAL_AVAILABILITY";
|
||||
releaseUpdate.refDocUrl = "http://docs.spring.io/spring/docs/{version}/spring-framework-reference/";
|
||||
releaseUpdate.apiDocUrl = "http://docs.spring.io/spring/docs/{version}/javadoc-api/";
|
||||
|
||||
Release release = this.client.createOrUpdateRelease("spring-framework", releaseUpdate);
|
||||
|
||||
then(release.releaseStatus).isEqualTo("GENERAL_AVAILABILITY");
|
||||
then(release.refDocUrl).isEqualTo("http://docs.spring.io/spring/docs/1.2.3.RELEASE/spring-framework-reference/");
|
||||
then(release.apiDocUrl).isEqualTo("http://docs.spring.io/spring/docs/1.2.3.RELEASE/javadoc-api/");
|
||||
then(release.groupId).isEqualTo("org.springframework");
|
||||
then(release.artifactId).isEqualTo("spring-context");
|
||||
then(release.version).isEqualTo("1.2.3.RELEASE");
|
||||
then(release.current).isFalse();
|
||||
then(release.generalAvailability).isTrue();
|
||||
then(release.preRelease).isFalse();
|
||||
then(release.versionDisplayName).isEqualTo("1.2.3");
|
||||
then(release.snapshot).isFalse();
|
||||
}
|
||||
|
||||
private SaganClient saganClient(ReleaserProperties properties) {
|
||||
RestTemplate restTemplate = restTemplate(properties);
|
||||
return new RestTemplateSaganClient(restTemplate, properties);
|
||||
}
|
||||
|
||||
private RestTemplate restTemplate(ReleaserProperties properties) {
|
||||
return new RestTemplateBuilder()
|
||||
.basicAuthorization(properties.getGit().getOauthToken(), "")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
static class Config {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package org.springframework.cloud.release.internal.sagan;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@AutoConfigureStubRunner(ids = "sagan:sagan-site")
|
||||
public class SaganClientTests {
|
||||
|
||||
@Value("${stubrunner.runningstubs.sagan-site.port}") Integer saganPort;
|
||||
|
||||
|
||||
}
|
||||
@@ -4,7 +4,6 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.springframework.cloud.internal</groupId>
|
||||
<artifactId>spring-cloud-release-tools-spring</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
@@ -26,6 +25,11 @@
|
||||
<artifactId>spring-cloud-release-tools-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jgit</groupId>
|
||||
<artifactId>org.eclipse.jgit</artifactId>
|
||||
<version>4.6.0.201612231935-r</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sf.jopt-simple</groupId>
|
||||
<artifactId>jopt-simple</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user