Sagan updates MC & RC too; fixes #22

This commit is contained in:
Marcin Grzejszczak
2017-10-24 08:27:50 +02:00
parent a4844c6d8f
commit eccea4e4fd
3 changed files with 34 additions and 18 deletions

View File

@@ -1,10 +1,11 @@
package org.springframework.cloud.release.internal.sagan;
import edu.emory.mathcs.backport.java.util.Collections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.release.internal.pom.ProjectVersion;
import edu.emory.mathcs.backport.java.util.Collections;
/**
* @author Marcin Grzejszczak
*/
@@ -19,21 +20,28 @@ public class SaganUpdater {
}
public void updateSagan(String branch, ProjectVersion originalVersion, ProjectVersion version) {
if (version.isMilestone() || version.isRc()) {
log.info("Won't update Sagan about milestones / rc");
return;
}
ReleaseUpdate update = new ReleaseUpdate();
update.groupId = originalVersion.groupId();
update.artifactId = version.projectName;
update.version = version.version;
update.releaseStatus = version.isSnapshot() ? "SNAPSHOT" : "GENERAL_AVAILABILITY";
update.releaseStatus = version(version);
update.apiDocUrl = referenceUrl(branch, version);
update.refDocUrl = referenceUrl(branch, version);
log.info("Updating Sagan with \n\n{}", update);
this.saganClient.updateRelease(version.projectName, Collections.singletonList(update));
}
private String version(ProjectVersion version) {
if (version.isSnapshot()) {
return "SNAPSHOT";
} else if (version.isMilestone() || version.isRc()) {
return "PRERELEASE";
} else if (version.isRelease() || version.isServiceRelease()) {
return "GENERAL_AVAILABILITY";
}
return "";
}
private String referenceUrl(String branch, ProjectVersion version) {
if (version.isRelease()) {
// static/sleuth/{version}/

View File

@@ -21,16 +21,20 @@ public class SaganUpdaterTest {
@Mock SaganClient saganClient;
@InjectMocks SaganUpdater saganUpdater;
@Test public void should_not_update_sagan_for_milestone_or_rc() throws Exception {
@Test public void should_update_sagan_for_milestone() throws Exception {
this.saganUpdater.updateSagan("master", version("1.0.0.M1"), version("1.0.0.M1"));
BDDMockito.then(this.saganClient).should(BDDMockito.never())
.updateRelease(BDDMockito.anyString(), BDDMockito.anyList());
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
BDDMockito.argThat(withReleaseUpdate("1.0.0.M1",
"http://cloud.spring.io/foo/foo.html", "PRERELEASE")));
}
@Test public void should_update_sagan_for_rc() throws Exception {
this.saganUpdater.updateSagan("master", version("1.0.0.RC1"), version("1.0.0.RC1"));
BDDMockito.then(this.saganClient).should(BDDMockito.never())
.updateRelease(BDDMockito.anyString(), BDDMockito.anyList());
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
BDDMockito.argThat(withReleaseUpdate("1.0.0.RC1",
"http://cloud.spring.io/foo/foo.html", "PRERELEASE")));
}
private ProjectVersion version(String version) {
@@ -43,7 +47,8 @@ public class SaganUpdaterTest {
this.saganUpdater.updateSagan("master", projectVersion, projectVersion);
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
BDDMockito.argThat(withReleaseUpdate("1.0.0.BUILD-SNAPSHOT", "http://cloud.spring.io/foo/foo.html")));
BDDMockito.argThat(withReleaseUpdate("1.0.0.BUILD-SNAPSHOT",
"http://cloud.spring.io/foo/foo.html", "SNAPSHOT")));
}
@Test public void should_update_sagan_from_release_version() throws Exception {
@@ -52,7 +57,8 @@ public class SaganUpdaterTest {
this.saganUpdater.updateSagan("master", projectVersion, projectVersion);
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
BDDMockito.argThat(withReleaseUpdate("1.0.0.RELEASE", "http://cloud.spring.io/spring-cloud-static/foo/{version}/")));
BDDMockito.argThat(withReleaseUpdate("1.0.0.RELEASE",
"http://cloud.spring.io/spring-cloud-static/foo/{version}/", "GENERAL_AVAILABILITY")));
}
@Test public void should_update_sagan_from_non_master() throws Exception {
@@ -61,14 +67,17 @@ public class SaganUpdaterTest {
this.saganUpdater.updateSagan("1.1.x", projectVersion, projectVersion);
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"),
BDDMockito.argThat(withReleaseUpdate("1.1.0.BUILD-SNAPSHOT", "http://cloud.spring.io/foo/1.1.x/")));
BDDMockito.argThat(withReleaseUpdate("1.1.0.BUILD-SNAPSHOT",
"http://cloud.spring.io/foo/1.1.x/", "SNAPSHOT")));
}
private TypeSafeMatcher<List<ReleaseUpdate>> withReleaseUpdate(final String version, final String refDocUrl) {
private TypeSafeMatcher<List<ReleaseUpdate>> withReleaseUpdate(final String version,
final String refDocUrl, final String releaseStatus) {
return new TypeSafeMatcher<List<ReleaseUpdate>>() {
@Override protected boolean matchesSafely(List<ReleaseUpdate> items) {
ReleaseUpdate item = items.get(0);
return "foo".equals(item.artifactId) &&
releaseStatus.equals(item.releaseStatus) &&
version.equals(item.version) &&
refDocUrl.equals(item.apiDocUrl) &&
refDocUrl.equals(item.refDocUrl);

View File

@@ -28,7 +28,6 @@ import org.springframework.cloud.release.internal.pom.ProjectVersion;
import org.springframework.cloud.release.internal.pom.TestPomReader;
import org.springframework.cloud.release.internal.pom.TestUtils;
import org.springframework.cloud.release.internal.project.ProjectBuilder;
import org.springframework.cloud.release.internal.sagan.ReleaseUpdate;
import org.springframework.cloud.release.internal.sagan.SaganClient;
import org.springframework.cloud.release.internal.sagan.SaganUpdater;
import org.springframework.cloud.release.internal.template.TemplateGenerator;
@@ -138,8 +137,8 @@ public class AcceptanceTests {
.contains("Dalston.RC1")
.contains("- Spring Cloud Build `1.3.1.RELEASE` ([issues](http://foo.bar.com/1.3.1.RELEASE))")
.contains("- Spring Cloud Bus `1.3.0.M1` ([issues](http://foo.bar.com/1.3.0.M1))");
BDDMockito.then(this.saganClient).should(BDDMockito.never()).updateRelease(
BDDMockito.anyString(), BDDMockito.anyList());
BDDMockito.then(this.saganClient).should().updateRelease(BDDMockito.eq("spring-cloud-consul"),
BDDMockito.anyList());
}
@Test