From e7fffd37ba4bad5f7faffe40b12ec56ff7bf05b8 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Tue, 16 Oct 2018 18:20:01 +0200 Subject: [PATCH] Switch for updating spring guides; fixes gh-101 --- .../release/internal/ReleaserProperties.java | 33 +++++++++++++++---- .../release/internal/git/GithubIssues.java | 5 +++ .../internal/git/GithubIssuesTests.java | 24 ++++++++++++-- 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/ReleaserProperties.java b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/ReleaserProperties.java index 90b3ce86..2e5c251d 100644 --- a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/ReleaserProperties.java +++ b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/ReleaserProperties.java @@ -185,6 +185,11 @@ public class ReleaserProperties implements Serializable { */ private Integer numberOfCheckedMilestones = 10; + /** + * If set to {@code false}, will not update Spring Guides for a release train. + */ + private boolean updateSpringGuides = true; + public String getSpringCloudReleaseGitUrl() { return this.springCloudReleaseGitUrl; } @@ -265,13 +270,27 @@ public class ReleaserProperties implements Serializable { this.fetchVersionsFromGit = fetchVersionsFromGit; } - @Override public String toString() { - return "Git{" + "springCloudReleaseGitUrl='" + this.springCloudReleaseGitUrl + '\'' - + ", documentationUrl='" + this.documentationUrl + '\'' - + ", documentationBranch='" + this.documentationBranch + '\'' - + ", cloneDestinationDir='" + this.cloneDestinationDir + '\'' - + ", fetchVersionsFromGit=" + this.fetchVersionsFromGit - + ", numberOfCheckedMilestones=" + this.numberOfCheckedMilestones + '}'; + public boolean isUpdateSpringGuides() { + return this.updateSpringGuides; + } + + public void setUpdateSpringGuides(boolean updateSpringGuides) { + this.updateSpringGuides = updateSpringGuides; + } + + @Override + public String toString() { + return "Git{" + + "springCloudReleaseGitUrl='" + this.springCloudReleaseGitUrl + '\'' + + ", documentationUrl='" + this.documentationUrl + '\'' + + ", documentationBranch='" + this.documentationBranch + '\'' + + ", updateDocumentationRepo=" + this.updateDocumentationRepo + + ", cloneDestinationDir='" + this.cloneDestinationDir + '\'' + + ", fetchVersionsFromGit=" + this.fetchVersionsFromGit + + ", oauthToken='" + this.oauthToken + '\'' + + ", numberOfCheckedMilestones=" + this.numberOfCheckedMilestones + + ", updateSpringGuides=" + this.updateSpringGuides + + '}'; } } diff --git a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/git/GithubIssues.java b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/git/GithubIssues.java index 4759e117..58dbe068 100644 --- a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/git/GithubIssues.java +++ b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/git/GithubIssues.java @@ -45,6 +45,11 @@ class GithubIssues { } void fileIssue(Projects projects, ProjectVersion version) { + if (!this.properties.getGit().isUpdateSpringGuides()) { + log.info("Will not file an issue to Spring Guides, since the switch to do so " + + "is off. Set [releaser.git.update-spring-guides] to [true] to change that"); + return; + } Assert.hasText(this.properties.getGit().getOauthToken(), "You have to pass Github OAuth token for milestone closing to be operational"); // do this only for RELEASE & SR diff --git a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GithubIssuesTests.java b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GithubIssuesTests.java index ac1e5cd9..b7f589eb 100644 --- a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GithubIssuesTests.java +++ b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GithubIssuesTests.java @@ -7,6 +7,7 @@ import java.util.Collections; import javax.json.Json; import com.jcabi.github.Coordinates; +import com.jcabi.github.Github; import com.jcabi.github.Issue; import com.jcabi.github.Milestone; import com.jcabi.github.Repo; @@ -15,6 +16,8 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import org.mockito.BDDMockito; + import org.springframework.boot.test.rule.OutputCapture; import org.springframework.cloud.release.internal.ReleaserProperties; import org.springframework.cloud.release.internal.pom.ProjectVersion; @@ -41,13 +44,30 @@ public class GithubIssuesTests { @Test public void should_not_do_anything_for_non_release_train_version() throws IOException { - GithubIssues issues = new GithubIssues(this.github, withToken()); + Github github = BDDMockito.mock(Github.class); + GithubIssues issues = new GithubIssues(github, withToken()); issues.fileIssue(new Projects( new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT") ), new ProjectVersion("sc-release", "Edgware.BUILD-SNAPSHOT")); - then(this.capture.toString()).contains("Guide issue creation will occur only"); + BDDMockito.then(github).shouldHaveZeroInteractions(); + } + + @Test + public void should_not_do_anything_if_switch_is_not_set() throws IOException { + Github github = BDDMockito.mock(Github.class); + ReleaserProperties properties = withToken(); + properties.getGit().setUpdateSpringGuides(false); + GithubIssues issues = new GithubIssues(github, properties); + + issues.fileIssue(new Projects( + new ProjectVersion("foo", "1.0.0.RELEASE"), + new ProjectVersion("bar", "2.0.0.RELEASE"), + new ProjectVersion("baz", "3.0.0.RELEASE") + ), new ProjectVersion("sc-release", "Edgware.RELEASE")); + + BDDMockito.then(github).shouldHaveZeroInteractions(); } @Test