From 78f059e44625fd9af515f4fd00c8477e7405abb0 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Wed, 20 Apr 2022 13:49:34 -0500 Subject: [PATCH] GitHubMilestoneHasNoOpenIssuesTask outputs to a file Rather than having the task fail if the milestone is not due today, it now outputs to a file true or false. This allows the pipeline to determine if it should continue or not without causing a failure. Closes gh-11158 --- .../GitHubMilestoneHasNoOpenIssuesTask.java | 20 +++++++++++++++---- .../milestones/GitHubMilestonePlugin.java | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestoneHasNoOpenIssuesTask.java b/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestoneHasNoOpenIssuesTask.java index fb0880aa91..4e5b538ed3 100644 --- a/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestoneHasNoOpenIssuesTask.java +++ b/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestoneHasNoOpenIssuesTask.java @@ -21,16 +21,21 @@ import org.gradle.api.file.RegularFileProperty; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputFile; import org.gradle.api.tasks.Optional; +import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; +import org.gradle.work.DisableCachingByDefault; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import org.springframework.gradle.github.RepositoryRef; +@DisableCachingByDefault(because = "the due date needs to be checked every time in case it changes") public abstract class GitHubMilestoneHasNoOpenIssuesTask extends DefaultTask { @Input private RepositoryRef repository = new RepositoryRef(); @@ -44,10 +49,13 @@ public abstract class GitHubMilestoneHasNoOpenIssuesTask extends DefaultTask { @Input @Optional private String gitHubAccessToken; + @OutputFile + public abstract RegularFileProperty getIsOpenIssuesFile(); + private GitHubMilestoneApi milestones = new GitHubMilestoneApi(); @TaskAction - public void checkHasNoOpenIssues() throws FileNotFoundException { + public void checkHasNoOpenIssues() throws IOException { if (this.milestoneTitle == null) { File nextVersionFile = getNextVersionFile().getAsFile().get(); Yaml yaml = new Yaml(new Constructor(NextVersionYml.class)); @@ -61,10 +69,14 @@ public abstract class GitHubMilestoneHasNoOpenIssuesTask extends DefaultTask { } long milestoneNumber = this.milestones.findMilestoneNumberByTitle(this.repository, this.milestoneTitle); boolean isOpenIssues = this.milestones.isOpenIssuesForMilestoneNumber(this.repository, milestoneNumber); + Path isOpenIssuesPath = getIsOpenIssuesFile().getAsFile().get().toPath(); + Files.writeString(isOpenIssuesPath, String.valueOf(isOpenIssues)); if (isOpenIssues) { - throw new IllegalStateException("The repository " + this.repository + " has open issues for milestone with the title " + this.milestoneTitle + " and number " + milestoneNumber); + System.out.println("The repository " + this.repository + " has open issues for milestone with the title " + this.milestoneTitle + " and number " + milestoneNumber); + } + else { + System.out.println("The repository " + this.repository + " has no open issues for milestone with the title " + this.milestoneTitle + " and number " + milestoneNumber); } - System.out.println("The repository " + this.repository + " has no open issues for milestone with the title " + this.milestoneTitle + " and number " + milestoneNumber); } public RepositoryRef getRepository() { diff --git a/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestonePlugin.java b/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestonePlugin.java index 261290985d..2dc92c2edf 100644 --- a/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestonePlugin.java +++ b/buildSrc/src/main/java/org/springframework/gradle/github/milestones/GitHubMilestonePlugin.java @@ -43,6 +43,7 @@ public class GitHubMilestonePlugin implements Plugin { public void execute(GitHubMilestoneHasNoOpenIssuesTask githubCheckMilestoneHasNoOpenIssues) { githubCheckMilestoneHasNoOpenIssues.setGroup("Release"); githubCheckMilestoneHasNoOpenIssues.setDescription("Checks if there are any open issues for the specified repository and milestone"); + githubCheckMilestoneHasNoOpenIssues.getIsOpenIssuesFile().value(project.getLayout().getBuildDirectory().file("github/milestones/is-open-issues")); githubCheckMilestoneHasNoOpenIssues.setMilestoneTitle((String) project.findProperty("nextVersion")); if (!project.hasProperty("nextVersion")) { githubCheckMilestoneHasNoOpenIssues.getNextVersionFile().convention(