@@ -102,7 +102,6 @@ public static List<String> runPostGenerationAndPublication(
102
102
public static List <String > validateNotes (Multimap <String , ReleaseNotesMessage > releaseNotes ,
103
103
CliOptions cliOptions ) {
104
104
final String releaseVersion = cliOptions .getReleaseNumber ();
105
- final long amountOfCommas = getAmountOfCommasInReleaseVersion (releaseVersion );
106
105
final boolean containsNewOrBreakingCompatabilityLabel =
107
106
releaseNotes .containsKey (Constants .NEW_FEATURE_LABEL )
108
107
|| releaseNotes .containsKey (Constants .NEW_MODULE_LABEL )
@@ -113,14 +112,14 @@ public static List<String> validateNotes(Multimap<String, ReleaseNotesMessage> r
113
112
final String errorEnding = "Please correct release number by running https://github.com/"
114
113
+ "checkstyle/checkstyle/actions/workflows/bump-version-and-update-milestone.yml" ;
115
114
116
- if (isPatch (amountOfCommas ) && containsNewOrBreakingCompatabilityLabel ) {
115
+ if (isPatch (releaseVersion ) && containsNewOrBreakingCompatabilityLabel ) {
117
116
errors .add (
118
117
String .format ("%s Release number is a patch(%s), but release notes contain 'new' "
119
118
+ "or 'breaking compatability' labels. %s" ,
120
119
errorBeginning , releaseVersion , errorEnding )
121
120
);
122
121
}
123
- else if (isMinor (amountOfCommas ) && !containsNewOrBreakingCompatabilityLabel ) {
122
+ else if (isMinor (releaseVersion ) && !containsNewOrBreakingCompatabilityLabel ) {
124
123
errors .add (
125
124
String .format ("%s Release number is minor(%s), but release notes do not contain "
126
125
+ "'new' or 'breaking compatability' labels. %s" ,
@@ -132,36 +131,35 @@ else if (isMinor(amountOfCommas) && !containsNewOrBreakingCompatabilityLabel) {
132
131
}
133
132
134
133
/**
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 .
137
136
*
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 .
140
139
*/
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 );
143
142
}
144
143
145
144
/**
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 .
148
147
*
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 .
151
150
*/
152
- private static boolean isPatch (long amountOfCommas ) {
153
- return amountOfCommas == 2 ;
151
+ private static boolean isPatch (String releaseVersion ) {
152
+ return ! endsWithZero ( releaseVersion ) ;
154
153
}
155
154
156
155
/**
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).
159
157
*
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) .
162
160
*/
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' ;
165
163
}
166
164
167
165
/**
0 commit comments