49
49
public class StashRepository {
50
50
private static final Logger logger =
51
51
Logger .getLogger (MethodHandles .lookup ().lookupClass ().getName ());
52
- private static final String BUILD_START_MARKER = "[*BuildStarted* **%s**] %s into %s" ;
53
- private static final String BUILD_FINISH_MARKER = "[*BuildFinished* **%s**] %s into %s" ;
54
- private static final String BUILD_CANCEL_MARKER = "[*BuildCanceled* **%s**] %s into %s" ;
55
-
56
- private static final String BUILD_START_REGEX =
57
- "\\ [\\ *BuildStarted\\ * \\ *\\ *%s\\ *\\ *\\ ] ([0-9a-fA-F]+) into ([0-9a-fA-F]+)" ;
58
- private static final String BUILD_FINISH_REGEX =
59
- "\\ [\\ *BuildFinished\\ * \\ *\\ *%s\\ *\\ *\\ ] ([0-9a-fA-F]+) into ([0-9a-fA-F]+)" ;
60
- private static final String BUILD_CANCEL_REGEX =
61
- "\\ [\\ *BuildCanceled\\ * \\ *\\ *%s\\ *\\ *\\ ] ([0-9a-fA-F]+) into ([0-9a-fA-F]+)" ;
62
- private static final String [] BUILD_REGEXES = {BUILD_START_REGEX , BUILD_FINISH_REGEX , BUILD_CANCEL_REGEX };
52
+ private static final String BUILD_START_MESSAGE = "BuildStarted" ;
53
+ private static final String BUILD_FINISH_MESSAGE = "BuildFinished" ;
54
+ private static final String BUILD_CANCEL_MESSAGE = "BuildCanceled" ;
55
+ private static final String [] BUILD_STATUSES = {BUILD_START_MESSAGE , BUILD_FINISH_MESSAGE , BUILD_CANCEL_MESSAGE };
56
+ private static final String BUILD_MARKER = "[*%s* **%s**] %s into %s" ;
57
+
58
+ private static final String BUILD_STATUS_REGEX =
59
+ "\\ [\\ *%s\\ * \\ *\\ *%s\\ *\\ *\\ ] ([0-9a-fA-F]+) into ([0-9a-fA-F]+)" ;
63
60
64
61
private static final String BUILD_FINISH_SENTENCE =
65
- BUILD_FINISH_MARKER + " %n%n **[%s](%s)** - Build *#%d* which took *%s*" ;
62
+ " %n%n **[%s](%s)** - Build *#%d* which took *%s*" ;
66
63
67
64
private static final String BUILD_SUCCESS_COMMENT = "✓ BUILD SUCCESS" ;
68
65
private static final String BUILD_FAILURE_COMMENT = "✕ BUILD FAILURE" ;
@@ -148,8 +145,8 @@ private boolean shouldSkip(StashPullRequestResponseValue pullRequest) {
148
145
149
146
private boolean isStatusMessage (String content ) {
150
147
String escapedBuildName = Pattern .quote (job .getDisplayName ());
151
- for (String pattern : BUILD_REGEXES ) {
152
- String buildStatusMessage = String .format (pattern , escapedBuildName );
148
+ for (String buildStatus : BUILD_STATUSES ) {
149
+ String buildStatusMessage = String .format (BUILD_STATUS_REGEX , buildStatus , escapedBuildName );
153
150
Matcher matcher =
154
151
Pattern .compile (buildStatusMessage , Pattern .CASE_INSENSITIVE ).matcher (content );
155
152
if (matcher .find ()) {
@@ -262,8 +259,8 @@ private List<StashPullRequestBuildTarget> getBuildTargetsWithoutOnlyBuildOnComme
262
259
263
260
// These will match any start or finish message -- need to check commits
264
261
String escapedBuildName = Pattern .quote (job .getDisplayName ());
265
- String project_build_start = String .format (BUILD_START_REGEX , escapedBuildName );
266
- String project_build_finished = String .format (BUILD_FINISH_REGEX , escapedBuildName );
262
+ String project_build_start = String .format (BUILD_STATUS_REGEX , BUILD_START_MESSAGE , escapedBuildName );
263
+ String project_build_finished = String .format (BUILD_STATUS_REGEX , BUILD_FINISH_MESSAGE , escapedBuildName );
267
264
Matcher startMatcher =
268
265
Pattern .compile (project_build_start , Pattern .CASE_INSENSITIVE ).matcher (content );
269
266
Matcher finishMatcher =
@@ -313,7 +310,7 @@ private List<StashPullRequestBuildTarget> getBuildTargetsWithoutOnlyBuildOnComme
313
310
private String postBuildStartComment (
314
311
StashPullRequestResponseValue pullRequest , Integer buildCommandCommentId )
315
312
throws StashApiException {
316
- return postBuildStatusComment (pullRequest , buildCommandCommentId , BUILD_START_MARKER );
313
+ return postBuildStatusComment (pullRequest , buildCommandCommentId , BUILD_START_MESSAGE );
317
314
}
318
315
319
316
/**
@@ -326,15 +323,15 @@ private String postBuildStartComment(
326
323
private String postBuildCancelComment (
327
324
StashPullRequestResponseValue pullRequest , Integer buildCommandCommentId )
328
325
throws StashApiException {
329
- return postBuildStatusComment (pullRequest , buildCommandCommentId , BUILD_CANCEL_MARKER );
326
+ return postBuildStatusComment (pullRequest , buildCommandCommentId , BUILD_CANCEL_MESSAGE );
330
327
}
331
328
332
329
private String postBuildStatusComment (
333
- StashPullRequestResponseValue pullRequest , Integer buildCommandCommentId , String marker )
330
+ StashPullRequestResponseValue pullRequest , Integer buildCommandCommentId , String buildMessage )
334
331
throws StashApiException {
335
332
String sourceCommit = pullRequest .getFromRef ().getLatestCommit ();
336
333
String destinationCommit = pullRequest .getToRef ().getLatestCommit ();
337
- String comment = format (marker , job .getDisplayName (), sourceCommit , destinationCommit );
334
+ String comment = format (BUILD_MARKER , buildMessage , job .getDisplayName (), sourceCommit , destinationCommit );
338
335
StashPullRequestComment commentResponse ;
339
336
commentResponse =
340
337
this .client .postPullRequestComment (pullRequest .getId (), comment , buildCommandCommentId );
@@ -582,10 +579,13 @@ public void postFinishedComment(
582
579
String message = getMessageForBuildResult (buildResult );
583
580
String comment =
584
581
format (
585
- BUILD_FINISH_SENTENCE ,
582
+ BUILD_MARKER ,
583
+ BUILD_FINISH_MESSAGE ,
586
584
job .getDisplayName (),
587
585
sourceCommit ,
588
- destinationCommit ,
586
+ destinationCommit )
587
+ + format (
588
+ BUILD_FINISH_SENTENCE ,
589
589
message ,
590
590
buildUrl ,
591
591
buildNumber ,
@@ -684,7 +684,7 @@ private void deletePreviousBuildFinishedComments(StashPullRequestResponseValue p
684
684
continue ;
685
685
}
686
686
687
- String project_build_finished = format (BUILD_FINISH_REGEX , job .getDisplayName ());
687
+ String project_build_finished = format (BUILD_STATUS_REGEX , BUILD_FINISH_MESSAGE , job .getDisplayName ());
688
688
Matcher finishMatcher =
689
689
Pattern .compile (project_build_finished , Pattern .CASE_INSENSITIVE ).matcher (content );
690
690
0 commit comments