diff --git a/releasenotes-builder/src/main/java/com/github/checkstyle/CliOptions.java b/releasenotes-builder/src/main/java/com/github/checkstyle/CliOptions.java index cb9898af..67f8a0e0 100644 --- a/releasenotes-builder/src/main/java/com/github/checkstyle/CliOptions.java +++ b/releasenotes-builder/src/main/java/com/github/checkstyle/CliOptions.java @@ -574,6 +574,8 @@ public Builder setTwitterProperties(String twProperties) { * * @param validate flag to validate release version. * @return Builder Object + * @noinspection ReturnOfInnerClass + * @noinspectionreason ReturnOfInnerClass - builder is only used in enclosing class */ public Builder setValidateVersion(boolean validate) { validateVersion = validate; diff --git a/releasenotes-builder/src/main/java/com/github/checkstyle/MainProcess.java b/releasenotes-builder/src/main/java/com/github/checkstyle/MainProcess.java index eb20e79e..ebaf619e 100644 --- a/releasenotes-builder/src/main/java/com/github/checkstyle/MainProcess.java +++ b/releasenotes-builder/src/main/java/com/github/checkstyle/MainProcess.java @@ -106,13 +106,15 @@ public static List validateNotes(Multimap r || releaseNotes.containsKey(Constants.BREAKING_COMPATIBILITY_LABEL); final List errors = new ArrayList<>(); - final String errorBeginning = "[ERROR] Validation of release number failed."; - final String errorEnding = "Please correct release number by running https://github.com/" - + "checkstyle/checkstyle/actions/workflows/bump-version-and-update-milestone.yml"; if (!RELEASE_PATTERN.matcher(releaseVersion).find()) { errors.add("Release number should match pattern " + RELEASE_NUMBER_PATTERN); } + + final String errorBeginning = "[ERROR] Validation of release number failed."; + final String errorEnding = "Please correct release number by running https://github.com/" + + "checkstyle/checkstyle/actions/workflows/bump-version-and-update-milestone.yml"; + if (isPatch(releaseVersion) && containsNewOrBreakingCompatabilityLabel) { errors.add( String.format("%s Release number is a patch(%s), but release notes contain 'new' " diff --git a/releasenotes-builder/src/main/java/com/github/checkstyle/globals/ReleaseNotesMessage.java b/releasenotes-builder/src/main/java/com/github/checkstyle/globals/ReleaseNotesMessage.java index dafc94ea..fd7b47dc 100644 --- a/releasenotes-builder/src/main/java/com/github/checkstyle/globals/ReleaseNotesMessage.java +++ b/releasenotes-builder/src/main/java/com/github/checkstyle/globals/ReleaseNotesMessage.java @@ -20,6 +20,7 @@ package com.github.checkstyle.globals; import java.util.Collections; +import java.util.regex.Pattern; import org.kohsuke.github.GHIssue; @@ -43,6 +44,9 @@ public final class ReleaseNotesMessage { private static final String TWELVE_SPACES = String.join( "", Collections.nCopies(TITLE_INDENTATION, " ")); + /** Pattern used to find things to escape in github. */ + private static final Pattern ESCAPE = Pattern.compile("([@<>&])"); + /** Issue number. */ private final int issueNo; /** Title. */ @@ -221,6 +225,6 @@ else if (ch == ' ') { * @return escaped string. */ private static String escapeGithubCharacters(String str) { - return str.replaceAll("(@|<|>|&)", "`$1`"); + return ESCAPE.matcher(str).replaceAll("`$1`"); } } diff --git a/releasenotes-builder/src/test/java/com/github/checkstyle/internal/AbstractReleaseNotesTestSupport.java b/releasenotes-builder/src/test/java/com/github/checkstyle/internal/AbstractReleaseNotesTestSupport.java index 0b9f79ab..edd5d24c 100644 --- a/releasenotes-builder/src/test/java/com/github/checkstyle/internal/AbstractReleaseNotesTestSupport.java +++ b/releasenotes-builder/src/test/java/com/github/checkstyle/internal/AbstractReleaseNotesTestSupport.java @@ -46,7 +46,6 @@ import org.kohsuke.github.GHRepository; import org.mockito.MockedStatic; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import com.github.checkstyle.Main; @@ -60,19 +59,15 @@ public abstract class AbstractReleaseNotesTestSupport extends AbstractPathTestSu private static final Set TEST_ISSUES = new LinkedHashSet<>(); - private static final Answer ISSUE_ANSWER = new Answer<>() { - @Override - public GHIssue answer(InvocationOnMock invocation) throws Throwable { - final int findIssue = invocation.getArgument(0); - - for (GHIssue item : TEST_ISSUES) { - if (item.getNumber() == findIssue) { - return item; - } + private static final Answer ISSUE_ANSWER = invocation -> { + final int findIssue = invocation.getArgument(0); + for (GHIssue item : TEST_ISSUES) { + if (item.getNumber() == findIssue) { + return item; } - - throw new GHFileNotFoundException("Cannot find Issue: " + findIssue); } + + throw new GHFileNotFoundException("Cannot find Issue: " + findIssue); }; private static boolean mocked; @@ -116,10 +111,9 @@ public void reset() { * * @param commitMessage The commit message to add. * @param author The commit author to add. - * @return {@code true} if the commit added is new. */ - protected boolean addCommit(String commitMessage, String author) { - return TEST_COMMITS.add(RevCommitUtil.create(commitMessage, author)); + protected void addCommit(String commitMessage, String author) { + TEST_COMMITS.add(RevCommitUtil.create(commitMessage, author)); } /** @@ -129,11 +123,10 @@ protected boolean addCommit(String commitMessage, String author) { * @param ghState The state of the issue. * @param ghTitle The title of the issue. * @param labels The labels of the issue. - * @return {@code true} if the issue added is new. */ - protected boolean addIssue(int ghNumber, GHIssueState ghState, String ghTitle, + protected void addIssue(int ghNumber, GHIssueState ghState, String ghTitle, String... labels) { - return TEST_ISSUES.add(GhIssueUtil.create(ghNumber, ghState, ghTitle, labels)); + TEST_ISSUES.add(GhIssueUtil.create(ghNumber, ghState, ghTitle, labels)); } /** diff --git a/releasenotes-builder/src/test/java/com/github/checkstyle/internal/RevCommitUtil.java b/releasenotes-builder/src/test/java/com/github/checkstyle/internal/RevCommitUtil.java index 70eb7ca7..f4e1d39a 100644 --- a/releasenotes-builder/src/test/java/com/github/checkstyle/internal/RevCommitUtil.java +++ b/releasenotes-builder/src/test/java/com/github/checkstyle/internal/RevCommitUtil.java @@ -19,7 +19,8 @@ package com.github.checkstyle.internal; -import java.util.Date; +import java.nio.charset.StandardCharsets; +import java.util.Calendar; import java.util.Random; import org.eclipse.jgit.revwalk.RevCommit; @@ -33,13 +34,15 @@ private RevCommitUtil() { public static RevCommit create(String commitMessage, String author) { final String commitData = String.format("tree %040x\n" + "parent %040x\n" - + "author " + author + " %d +0100\n" - + "committer " + author + " %d +0100\n\n" + + "author %s %d +0100\n" + + "committer %s %d +0100\n\n" + commitMessage, RANDOM.nextLong(), RANDOM.nextLong(), - new Date().getTime(), - new Date().getTime()); - return RevCommit.parse(commitData.getBytes()); + author, + Calendar.getInstance().getTime().getTime(), + author, + Calendar.getInstance().getTime().getTime()); + return RevCommit.parse(commitData.getBytes(StandardCharsets.UTF_8)); } }