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 2 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
3 changes: 3 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.'
reyamam marked this conversation as resolved.
Show resolved Hide resolved
],
scoreConfig: [
issueFilterConfig: [
Expand Down Expand Up @@ -415,6 +416,8 @@ 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.'
reyamam marked this conversation as resolved.
Show resolved Hide resolved

],
scoreConfig: [
issueFilterConfig: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@
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 Expand Up @@ -378,6 +380,12 @@
backCompatibilityHelper.setPath(path);
}

@Deprecated
@DataBoundSetter
public void setOmitDuplicateComments(boolean omitDuplicateComments) {
backCompatibilityHelper.setOmitDuplicateComments(omitDuplicateComments);

Check warning on line 386 in src/main/java/org/jenkinsci/plugins/sonargerrit/SonarToGerritPublisher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 386 is not covered by tests
}

Check warning on line 387 in src/main/java/org/jenkinsci/plugins/sonargerrit/SonarToGerritPublisher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 387 is not covered by tests
reyamam marked this conversation as resolved.
Show resolved Hide resolved

@Deprecated
public String getSonarURL() {
return backCompatibilityHelper.getSonarURL();
Expand All @@ -398,6 +406,11 @@
return backCompatibilityHelper.isNewIssuesOnly();
}

@Deprecated
public boolean isOmitDuplicateComments() {
return backCompatibilityHelper.isOmitDuplicateComments();

Check warning on line 411 in src/main/java/org/jenkinsci/plugins/sonargerrit/SonarToGerritPublisher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 411 is not covered by tests
}

reyamam marked this conversation as resolved.
Show resolved Hide resolved
@Deprecated
public boolean isChangedLinesOnly() {
return backCompatibilityHelper.isChangedLinesOnly();
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,15 +39,19 @@ 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,
String someIssuesTitleTemplate,
String issueCommentTemplate) {
String issueCommentTemplate,
boolean omitDuplicateComments) {
reyamam marked this conversation as resolved.
Show resolved Hide resolved
setIssueFilterConfig(issueFilterConfig);
setNoIssuesTitleTemplate(noIssuesTitleTemplate);
setSomeIssuesTitleTemplate(someIssuesTitleTemplate);
setIssueCommentTemplate(issueCommentTemplate);
setOmitDuplicateComments(omitDuplicateComments);
reyamam marked this conversation as resolved.
Show resolved Hide resolved
}

@DataBoundConstructor
Expand All @@ -56,7 +60,8 @@ public ReviewConfig() {
new IssueFilterConfig(),
DescriptorImpl.NO_ISSUES_TITLE_TEMPLATE,
DescriptorImpl.SOME_ISSUES_TITLE_TEMPLATE,
DescriptorImpl.ISSUE_COMMENT_TEMPLATE);
DescriptorImpl.ISSUE_COMMENT_TEMPLATE,
DescriptorImpl.ISSUE_OMIT_DUPLICATE_COMMENTS);
reyamam marked this conversation as resolved.
Show resolved Hide resolved
}

public ReviewCommentType getCommentType() {
Expand Down Expand Up @@ -114,6 +119,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 +143,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason to populate this class. If I remember correctly, as its name indicates, it is only kept for backward compatibility reason and therefore should not be enriched anymore.

Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
reviewConfig.setIssueCommentTemplate(issueComment);
}

public void setOmitDuplicateComments(boolean omitDuplicateComments) {
ReviewConfig reviewConfig = getOrCreateReviewConfig();

Check warning on line 154 in src/main/java/org/jenkinsci/plugins/sonargerrit/util/BackCompatibilityHelper.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 154 is not covered by tests
reviewConfig.setOmitDuplicateComments(omitDuplicateComments);

Check warning on line 155 in src/main/java/org/jenkinsci/plugins/sonargerrit/util/BackCompatibilityHelper.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 155 is not covered by tests
}

Check warning on line 156 in src/main/java/org/jenkinsci/plugins/sonargerrit/util/BackCompatibilityHelper.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 156 is not covered by tests

reyamam marked this conversation as resolved.
Show resolved Hide resolved
// set up Authentication Context

public void setOverrideCredentials(Boolean overrideCredentials) {
Expand Down Expand Up @@ -245,6 +250,10 @@
return false;
}

public boolean isOmitDuplicateComments() {
return false;

Check warning on line 254 in src/main/java/org/jenkinsci/plugins/sonargerrit/util/BackCompatibilityHelper.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 254 is not covered by tests
}

reyamam marked this conversation as resolved.
Show resolved Hide resolved
public boolean isChangedLinesOnly() {
return false;
}
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 @@ -81,14 +81,15 @@ protected void doTestReviewConfig() {
Assertions.assertEquals(NEW_ISSUES_ONLY, config.getIssueFilterConfig().isNewIssuesOnly());
Assertions.assertEquals(CHANGED_LINES_ONLY, config.getIssueFilterConfig().isChangedLinesOnly());

config = new ReviewConfig(null, null, null, null);
config = new ReviewConfig(null, null, null, null, false);
reyamam marked this conversation as resolved.
Show resolved Hide resolved
Assertions.assertNotNull(config.getIssueFilterConfig());
Assertions.assertEquals(SEVERITY, config.getIssueFilterConfig().getSeverity());
Assertions.assertEquals(NEW_ISSUES_ONLY, config.getIssueFilterConfig().isNewIssuesOnly());
Assertions.assertEquals(CHANGED_LINES_ONLY, config.getIssueFilterConfig().isChangedLinesOnly());
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