@@ -219,7 +219,7 @@ private void createPost(String token, String postJson) {
219219 }
220220 }
221221
222- private String createPostJson (String projectName , String versionRef ) {
222+ private static String createPostJson (String projectName , String versionRef ) {
223223 String version = versionRef .startsWith ("v" ) ? versionRef .substring (1 ) : versionRef ;
224224 String changelogUrl = getChangelogUrl (projectName , versionRef );
225225 String postText = "%s %s has been released!\\ n\\ nCheck out the changelog at %s" .formatted (projectName ,
@@ -236,20 +236,14 @@ private String createPostJson(String projectName, String versionRef) {
236236 }""" .formatted (postText , ZonedDateTime .now ().format (DateTimeFormatter .ISO_INSTANT ), facetsJson );
237237 }
238238
239- private String getChangelogUrl (String projectName , String versionRef ) {
239+ private static String getChangelogUrl (String projectName , String versionRef ) {
240240 return "https://github.com/micrometer-metrics/%s/releases/tag/%s" .formatted (projectName , versionRef );
241241 }
242242
243- private String createFacetsJson (String postText , String changelogUrl ) {
243+ private static String createFacetsJson (String postText , String changelogUrl ) {
244244 int urlBytesLength = changelogUrl .getBytes (StandardCharsets .UTF_8 ).length ;
245- byte [] postBytes = postText .getBytes (StandardCharsets .UTF_8 );
246- int newLineBytes = "\n " .getBytes (StandardCharsets .UTF_8 ).length ;
247- int newLineLiteralBytes = "\\ n" .getBytes (StandardCharsets .UTF_8 ).length ;
248- int newLineLiteralCount = postText .split ("\\ \\ n" , -1 ).length - 1 ;
249- // we send new line literals `\n` but the bytes are counted as newline chars
250- // subtract the difference in bytes for each new line in the post text
251- int postLength = postBytes .length - newLineLiteralCount * (newLineLiteralBytes - newLineBytes );
252- int bytesStart = postLength - urlBytesLength ;
245+ int postBytesLength = getPostBytesLength (postText );
246+ int bytesStart = postBytesLength - urlBytesLength ;
253247 return """
254248 {
255249 "index": {
@@ -262,7 +256,17 @@ private String createFacetsJson(String postText, String changelogUrl) {
262256 "uri": "%s"
263257 }
264258 ]
265- }""" .formatted (bytesStart , postLength , changelogUrl );
259+ }""" .formatted (bytesStart , postBytesLength , changelogUrl );
260+ }
261+
262+ private static int getPostBytesLength (String postText ) {
263+ byte [] postBytes = postText .getBytes (StandardCharsets .UTF_8 );
264+ int newLineBytes = "\n " .getBytes (StandardCharsets .UTF_8 ).length ;
265+ int newLineLiteralBytes = "\\ n" .getBytes (StandardCharsets .UTF_8 ).length ;
266+ int newLineLiteralCount = postText .split ("\\ \\ n" , -1 ).length - 1 ;
267+ // we send new line literals `\n` but the bytes are counted as newline chars
268+ // subtract the difference in bytes for each new line in the post text
269+ return postBytes .length - newLineLiteralCount * (newLineLiteralBytes - newLineBytes );
266270 }
267271
268272 }
0 commit comments