diff --git a/src/main/java/pl/touk/sputnik/configuration/GeneralOption.java b/src/main/java/pl/touk/sputnik/configuration/GeneralOption.java index 4b8c26ee..0f72b343 100644 --- a/src/main/java/pl/touk/sputnik/configuration/GeneralOption.java +++ b/src/main/java/pl/touk/sputnik/configuration/GeneralOption.java @@ -17,6 +17,7 @@ public enum GeneralOption implements ConfigurationOption { MESSAGE_COMMENT_FORMAT("message.commentFormat", "Sputnik comment format. {0}: reporter, {1}: level, {2}: message", "[{0}] {1}: {2}"), MESSAGE_PROBLEM_FORMAT("message.problemFormat", "Sputnik problem format. {0}: reporter, {1}: message", "There is a problem with {0}: {1}"), + MESSAGE_PASSING_COMMENT_ENABLED("message.passingCommentEnabled", "Passing Comment enabled", "true"), MESSAGE_SCORE_PASSING_COMMENT("message.scorePassingComment", "Comment when no errors are found", "Perfect!"), CONNECTOR_TYPE("connector.type", "Connector: ", ConnectorType.GERRIT.getName()), diff --git a/src/main/java/pl/touk/sputnik/engine/VisitorBuilder.java b/src/main/java/pl/touk/sputnik/engine/VisitorBuilder.java index 9f785bcf..f1b4f374 100644 --- a/src/main/java/pl/touk/sputnik/engine/VisitorBuilder.java +++ b/src/main/java/pl/touk/sputnik/engine/VisitorBuilder.java @@ -65,7 +65,9 @@ public List buildAfterReviewVisitors(@Nonnull Configuration addCommentVisitor(afterReviewVisitors, configuration, connectorFacade); - String passingComment = configuration.getProperty(GeneralOption.MESSAGE_SCORE_PASSING_COMMENT); + String passingComment= null; + if (configuration.getProperty(GeneralOption.MESSAGE_PASSING_COMMENT_ENABLED)) + passingComment = configuration.getProperty(GeneralOption.MESSAGE_SCORE_PASSING_COMMENT); afterReviewVisitors.add(new SummaryMessageVisitor(passingComment)); int maxNumberOfComments = NumberUtils.toInt(configuration.getProperty(GeneralOption.MAX_NUMBER_OF_COMMENTS), 0); diff --git a/src/main/java/pl/touk/sputnik/engine/visitor/SummaryMessageVisitor.java b/src/main/java/pl/touk/sputnik/engine/visitor/SummaryMessageVisitor.java index 9bfae9dc..0bbedcc3 100644 --- a/src/main/java/pl/touk/sputnik/engine/visitor/SummaryMessageVisitor.java +++ b/src/main/java/pl/touk/sputnik/engine/visitor/SummaryMessageVisitor.java @@ -22,6 +22,8 @@ public void afterReview(@NotNull Review review) { private void addSummaryMessage(Review review) { String summaryMessage = getSummaryMessage(review); + if (summaryMessage == null) return; + log.info("Adding summary message to review: {}", summaryMessage); review.getMessages().add(summaryMessage); } diff --git a/src/test/java/pl/touk/sputnik/engine/visitor/SummaryMessageVisitorTest.java b/src/test/java/pl/touk/sputnik/engine/visitor/SummaryMessageVisitorTest.java index 5ebe8968..48fc254e 100644 --- a/src/test/java/pl/touk/sputnik/engine/visitor/SummaryMessageVisitorTest.java +++ b/src/test/java/pl/touk/sputnik/engine/visitor/SummaryMessageVisitorTest.java @@ -60,6 +60,15 @@ void shouldAddPerfectMessageIfThereAreNoViolationsFound() { assertThat(review.getMessages()).containsOnly("Perfect"); } + @Test + void shouldNotAddPerfectMessageIfThereAreNoViolationsFound() { + when(review.getTotalViolationCount()).thenReturn(0L); + + noPerfectSummaryMessageVisitor.afterReview(review); + + assertThat(review.getMessages()).isEmpty(); + } + @Test void shouldAddProblemMessagesPerfectMessageIfThereAreNoViolationsFound() { when(review.getTotalViolationCount()).thenReturn(8L);