Skip to content

Commit

Permalink
Issue #614: resolves idea violations
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach authored and romani committed Dec 30, 2022
1 parent 6a8a86c commit 44e4c77
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ public static List<String> validateNotes(Multimap<String, ReleaseNotesMessage> r
|| releaseNotes.containsKey(Constants.BREAKING_COMPATIBILITY_LABEL);

final List<String> 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' "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.github.checkstyle.globals;

import java.util.Collections;
import java.util.regex.Pattern;

import org.kohsuke.github.GHIssue;

Expand All @@ -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. */
Expand Down Expand Up @@ -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`");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -60,19 +59,15 @@ public abstract class AbstractReleaseNotesTestSupport extends AbstractPathTestSu

private static final Set<GHIssue> TEST_ISSUES = new LinkedHashSet<>();

private static final Answer<GHIssue> 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<GHIssue> 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;
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 + " <test@email.com> %d +0100\n"
+ "committer " + author + " <test@email.com> %d +0100\n\n"
+ "author %s <test@email.com> %d +0100\n"
+ "committer %s <test@email.com> %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));
}
}

0 comments on commit 44e4c77

Please sign in to comment.