Skip to content

Issue #701: releasenotes builder: release version validation should work on digits #706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public static List<String> runPostGenerationAndPublication(
public static List<String> validateNotes(Multimap<String, ReleaseNotesMessage> releaseNotes,
CliOptions cliOptions) {
final String releaseVersion = cliOptions.getReleaseNumber();
final long amountOfCommas = getAmountOfCommasInReleaseVersion(releaseVersion);
final boolean containsNewOrBreakingCompatabilityLabel =
releaseNotes.containsKey(Constants.NEW_FEATURE_LABEL)
|| releaseNotes.containsKey(Constants.NEW_MODULE_LABEL)
Expand All @@ -113,14 +112,14 @@ public static List<String> validateNotes(Multimap<String, ReleaseNotesMessage> r
final String errorEnding = "Please correct release number by running https://github.com/"
+ "checkstyle/checkstyle/actions/workflows/bump-version-and-update-milestone.yml";

if (isPatch(amountOfCommas) && containsNewOrBreakingCompatabilityLabel) {
if (isPatch(releaseVersion) && containsNewOrBreakingCompatabilityLabel) {
errors.add(
String.format("%s Release number is a patch(%s), but release notes contain 'new' "
+ "or 'breaking compatability' labels. %s",
errorBeginning, releaseVersion, errorEnding)
);
}
else if (isMinor(amountOfCommas) && !containsNewOrBreakingCompatabilityLabel) {
else if (isMinor(releaseVersion) && !containsNewOrBreakingCompatabilityLabel) {
errors.add(
String.format("%s Release number is minor(%s), but release notes do not contain "
+ "'new' or 'breaking compatability' labels. %s",
Expand All @@ -132,36 +131,35 @@ else if (isMinor(amountOfCommas) && !containsNewOrBreakingCompatabilityLabel) {
}

/**
* Retrieves the amount of commas in the release version. For instance,
* 10.3.3 would return {@code 2}.
* Check if a release version is minor. A release version is minor when
* it ends with a zero(0), for example 10.4.0.
*
* @param releaseVersion release number in the command line interface.
* @return amount of commas in release version.
* @param releaseVersion checkstyle release version.
* @return {@code true} if release version is minor.
*/
private static long getAmountOfCommasInReleaseVersion(String releaseVersion) {
return releaseVersion.chars().filter(character -> character == '.').count();
private static boolean isMinor(String releaseVersion) {
return endsWithZero(releaseVersion);
}

/**
* Returns {@code true} if amount of commas is 2. This means
* the release is a patch.
* Check if a release version is minor. A release version is minor when
* it ends with any other digit but a zero(0), for example 10.4.1.
*
* @param amountOfCommas amount of commas in release number.
* @return {@code true} if amount of commas is 2.
* @param releaseVersion checkstyle release version.
* @return {@code true} if release version is patch.
*/
private static boolean isPatch(long amountOfCommas) {
return amountOfCommas == 2;
private static boolean isPatch(String releaseVersion) {
return !endsWithZero(releaseVersion);
}

/**
* Returns {@code true} if amount of commas is 1. This means
* the release is minor.
* Check if provided string ends with a zero(0).
*
* @param amountOfCommas amount of commas in release number.
* @return {@code true} if amount of commas is 1.
* @param str string to check.
* @return {@code true} if string to check ends with a zero(0).
*/
private static boolean isMinor(long amountOfCommas) {
return amountOfCommas == 1;
private static boolean endsWithZero(String str) {
return !str.isEmpty() && str.charAt(str.length() - 1) == '0';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that this method sounds redundant and we could have used built-in str.endsWith("0") but Intellij suggests using this instead so I went with it.

}

/**
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Checkstyle 1.0.0 - https://checkstyle.org/releasenotes.html#Release_1.0.0
Checkstyle 1.0.1 - https://checkstyle.org/releasenotes.html#Release_1.0.1



Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Checkstyle 1.0.0 - https://checkstyle.org/releasenotes.html#Release_1.0.0
Checkstyle 1.0.1 - https://checkstyle.org/releasenotes.html#Release_1.0.1



Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Checkstyle 1.0.0 - https://checkstyle.org/releasenotes.html#Release_1.0.0
Checkstyle 1.0.1 - https://checkstyle.org/releasenotes.html#Release_1.0.1



Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Checkstyle 1.0.0 - https://checkstyle.org/releasenotes.html#Release_1.0.0
Checkstyle 1.0.1 - https://checkstyle.org/releasenotes.html#Release_1.0.1

Bug fixes: 10
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Checkstyle 1.0.0 - https://checkstyle.org/releasenotes.html#Release_1.0.0
Checkstyle 1.0.1 - https://checkstyle.org/releasenotes.html#Release_1.0.1

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<section name="Release 1.0.0">
<section name="Release 1.0.1">
<div class="releaseDate">XX.XX.XXXX</div>
<p>Bug fixes:</p>
<ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<section name="Release 1.0.0">
<section name="Release 1.0.1">
<div class="releaseDate">XX.XX.XXXX</div>
<p>Notes:</p>
<ul>
Expand Down