Skip to content

Commit b412c47

Browse files
stoyanK7romani
authored andcommitted
Issue #701: releasenotes builder: release version validation should work on digits
1 parent 5fe4360 commit b412c47

File tree

10 files changed

+57
-59
lines changed

10 files changed

+57
-59
lines changed

releasenotes-builder/.attach_pid15148

Whitespace-only changes.

releasenotes-builder/src/main/java/com/github/checkstyle/MainProcess.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public static List<String> runPostGenerationAndPublication(
102102
public static List<String> validateNotes(Multimap<String, ReleaseNotesMessage> releaseNotes,
103103
CliOptions cliOptions) {
104104
final String releaseVersion = cliOptions.getReleaseNumber();
105-
final long amountOfCommas = getAmountOfCommasInReleaseVersion(releaseVersion);
106105
final boolean containsNewOrBreakingCompatabilityLabel =
107106
releaseNotes.containsKey(Constants.NEW_FEATURE_LABEL)
108107
|| releaseNotes.containsKey(Constants.NEW_MODULE_LABEL)
@@ -113,14 +112,14 @@ public static List<String> validateNotes(Multimap<String, ReleaseNotesMessage> r
113112
final String errorEnding = "Please correct release number by running https://github.com/"
114113
+ "checkstyle/checkstyle/actions/workflows/bump-version-and-update-milestone.yml";
115114

116-
if (isPatch(amountOfCommas) && containsNewOrBreakingCompatabilityLabel) {
115+
if (isPatch(releaseVersion) && containsNewOrBreakingCompatabilityLabel) {
117116
errors.add(
118117
String.format("%s Release number is a patch(%s), but release notes contain 'new' "
119118
+ "or 'breaking compatability' labels. %s",
120119
errorBeginning, releaseVersion, errorEnding)
121120
);
122121
}
123-
else if (isMinor(amountOfCommas) && !containsNewOrBreakingCompatabilityLabel) {
122+
else if (isMinor(releaseVersion) && !containsNewOrBreakingCompatabilityLabel) {
124123
errors.add(
125124
String.format("%s Release number is minor(%s), but release notes do not contain "
126125
+ "'new' or 'breaking compatability' labels. %s",
@@ -132,36 +131,35 @@ else if (isMinor(amountOfCommas) && !containsNewOrBreakingCompatabilityLabel) {
132131
}
133132

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

145144
/**
146-
* Returns {@code true} if amount of commas is 2. This means
147-
* the release is a patch.
145+
* Check if a release version is minor. A release version is minor when
146+
* it ends with any other digit but a zero(0), for example 10.4.1.
148147
*
149-
* @param amountOfCommas amount of commas in release number.
150-
* @return {@code true} if amount of commas is 2.
148+
* @param releaseVersion checkstyle release version.
149+
* @return {@code true} if release version is patch.
151150
*/
152-
private static boolean isPatch(long amountOfCommas) {
153-
return amountOfCommas == 2;
151+
private static boolean isPatch(String releaseVersion) {
152+
return !endsWithZero(releaseVersion);
154153
}
155154

156155
/**
157-
* Returns {@code true} if amount of commas is 1. This means
158-
* the release is minor.
156+
* Check if provided string ends with a zero(0).
159157
*
160-
* @param amountOfCommas amount of commas in release number.
161-
* @return {@code true} if amount of commas is 1.
158+
* @param str string to check.
159+
* @return {@code true} if string to check ends with a zero(0).
162160
*/
163-
private static boolean isMinor(long amountOfCommas) {
164-
return amountOfCommas == 1;
161+
private static boolean endsWithZero(String str) {
162+
return !str.isEmpty() && str.charAt(str.length() - 1) == '0';
165163
}
166164

167165
/**

releasenotes-builder/src/test/java/com/github/checkstyle/templates/TemplateProcessorTest.java

Lines changed: 31 additions & 31 deletions
Large diffs are not rendered by default.

releasenotes-builder/src/test/resources/com/github/checkstyle/githubPageBug.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Checkstyle 1.0.0 - https://checkstyle.org/releasenotes.html#Release_1.0.0
1+
Checkstyle 1.0.1 - https://checkstyle.org/releasenotes.html#Release_1.0.1
22

33

44

releasenotes-builder/src/test/resources/com/github/checkstyle/rssMlistBug.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Checkstyle 1.0.0 - https://checkstyle.org/releasenotes.html#Release_1.0.0
1+
Checkstyle 1.0.1 - https://checkstyle.org/releasenotes.html#Release_1.0.1
22

33

44

releasenotes-builder/src/test/resources/com/github/checkstyle/rssMlistMisc.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Checkstyle 1.0.0 - https://checkstyle.org/releasenotes.html#Release_1.0.0
1+
Checkstyle 1.0.1 - https://checkstyle.org/releasenotes.html#Release_1.0.1
22

33

44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Checkstyle 1.0.0 - https://checkstyle.org/releasenotes.html#Release_1.0.0
1+
Checkstyle 1.0.1 - https://checkstyle.org/releasenotes.html#Release_1.0.1
22

33
Bug fixes: 10
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Checkstyle 1.0.0 - https://checkstyle.org/releasenotes.html#Release_1.0.0
1+
Checkstyle 1.0.1 - https://checkstyle.org/releasenotes.html#Release_1.0.1
22

releasenotes-builder/src/test/resources/com/github/checkstyle/xdocBug.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
<section name="Release 1.0.0">
2+
<section name="Release 1.0.1">
33
<div class="releaseDate">XX.XX.XXXX</div>
44
<p>Bug fixes:</p>
55
<ul>

releasenotes-builder/src/test/resources/com/github/checkstyle/xdocMisc.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
<section name="Release 1.0.0">
2+
<section name="Release 1.0.1">
33
<div class="releaseDate">XX.XX.XXXX</div>
44
<p>Notes:</p>
55
<ul>

0 commit comments

Comments
 (0)