Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an optiona allowing to prevent duplicated comments on subsequent patchsets #145

Merged
merged 4 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ node {
noIssuesTitleTemplate : 'SonarQube violations have not been found.',
someIssuesTitleTemplate: '<total_count> SonarQube violations have been found.',
issueCommentTemplate : '<severity> SonarQube violation:\n\n\n<message>\n\n\nRead more: <rule_url>'
omitDuplicateComments : 'If true, comments with the same content at the same place will be omitted by Gerrit. Defaults to false.'
],
scoreConfig: [
issueFilterConfig: [
Expand Down Expand Up @@ -415,6 +416,7 @@ node {
noIssuesTitleTemplate : 'SonarQube violations have not been found.',
someIssuesTitleTemplate: '<total_count> SonarQube violations have been found.',
issueCommentTemplate : '<severity> SonarQube violation:\n\n\n<message>\n\n\nRead more: <rule_url>'
omitDuplicateComments : 'If true, comments with the same content at the same place will be omitted by Gerrit. Defaults to false.'
],
scoreConfig: [
issueFilterConfig: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Publisher>
public static final String ISSUE_COMMENT_TEXT =
Localization.getLocalized("jenkins.plugin.default.review.body");

public static final boolean ISSUE_OMIT_DUPLICATE_COMMENTS = false;

public static final String CATEGORY = "Code-Review";
public static final Integer NO_ISSUES_SCORE = 1;
public static final Integer SOME_ISSUES_SCORE = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public ReviewInput buildReview() {
String reviewMessage = getReviewMessage(finalIssuesToComment);
ReviewInput reviewInput = new ReviewInput().message(reviewMessage);
reviewInput.tag = "autogenerated:sonar";
reviewInput.omitDuplicateComments = reviewConfig.isOmitDuplicateComments();

switch (reviewConfig.getCommentType()) {
case STANDARD:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class ReviewConfig extends AbstractDescribableImpl<ReviewConfig> {
* */
@Nonnull private String issueCommentTemplate = DescriptorImpl.ISSUE_COMMENT_TEMPLATE;

private boolean omitDuplicateComments = DescriptorImpl.ISSUE_OMIT_DUPLICATE_COMMENTS;

public ReviewConfig(
IssueFilterConfig issueFilterConfig,
String noIssuesTitleTemplate,
Expand Down Expand Up @@ -114,6 +116,15 @@ public void setIssueCommentTemplate(String issueCommentTemplate) {
Util.fixEmptyAndTrim(issueCommentTemplate), DescriptorImpl.ISSUE_COMMENT_TEMPLATE);
}

public boolean isOmitDuplicateComments() {
return omitDuplicateComments;
}

@DataBoundSetter
public void setOmitDuplicateComments(boolean omitDuplicateComments) {
this.omitDuplicateComments = omitDuplicateComments;
}

@Override
public DescriptorImpl getDescriptor() {
return new DescriptorImpl();
Expand All @@ -129,6 +140,9 @@ public static class DescriptorImpl extends Descriptor<ReviewConfig> {
public static final String ISSUE_COMMENT_TEMPLATE =
SonarToGerritPublisher.DescriptorImpl.ISSUE_COMMENT_TEXT;

public static final boolean ISSUE_OMIT_DUPLICATE_COMMENTS =
SonarToGerritPublisher.DescriptorImpl.ISSUE_OMIT_DUPLICATE_COMMENTS;

@SuppressWarnings(value = "unused")
public String getCommentTypeDisplayName(ReviewCommentType commentType) {
return commentType.displayName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@
placeholder="${descriptor.ISSUE_COMMENT_TEMPLATE}"/>
</f:entry>

<f:entry
title="${%jenkins.plugin.settings.gerrit.review.omit.duplicate.comments}"
field="omitDuplicateComments"
value="${omitDuplicateComments}"
description="${%jenkins.plugin.settings.gerrit.review.omit.duplicate.comments.description}">
<f:checkbox selected="${omitDuplicateComments}" default="descriptor.ISSUE_OMIT_DUPLICATE_COMMENTS"/>
</f:entry>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ jenkins.plugin.settings.gerrit.review.template=Report Template
jenkins.plugin.settings.gerrit.review.template.title.no.issues=No issues found review title template
jenkins.plugin.settings.gerrit.review.template.title.issues=Issues found review title template
jenkins.plugin.settings.gerrit.review.template.body=Issue comment template
jenkins.plugin.settings.gerrit.review.omit.duplicate.comments=Omit duplicate comments?
jenkins.plugin.settings.gerrit.review.omit.duplicate.comments.description=If true, comments with the same content at the same place will be omitted by Gerrit.

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public abstract class DetailedConfigTest extends BaseConfigTest {
protected static final boolean PATH_AUTO_MATCH =
PreviewModeAnalysisStrategy.DescriptorImpl.AUTO_MATCH;

protected static final boolean ISSUE_OMIT_DUPLICATE_COMMENTS =
ReviewConfig.DescriptorImpl.ISSUE_OMIT_DUPLICATE_COMMENTS;

// IssueFilterConfig

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected void doTestReviewConfig() {
Assertions.assertEquals(NO_ISSUES_TITLE_TEMPLATE, config.getNoIssuesTitleTemplate());
Assertions.assertEquals(SOME_ISSUES_TITLE_TEMPLATE, config.getSomeIssuesTitleTemplate());
Assertions.assertEquals(ISSUE_COMMENT_TEMPLATE, config.getIssueCommentTemplate());
Assertions.assertEquals(ISSUE_OMIT_DUPLICATE_COMMENTS, config.isOmitDuplicateComments());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public void testNoScoreConfig() {
publisher.setScoreConfig(null);
ReviewInput reviewResult = getReviewResult();
Assertions.assertNull(reviewResult.labels);
Assertions.assertFalse(reviewResult.omitDuplicateComments);
}

@Test
public void testOmitDuplicateCommentsSet() {
getReviewConfig().setOmitDuplicateComments(true);
ReviewInput reviewResult = getReviewResult();
Assertions.assertTrue(reviewResult.omitDuplicateComments);
}

protected ReviewInput getReviewResult() {
Expand Down
Loading