]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16316 Add resolution and comments
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 23 May 2022 15:24:26 +0000 (17:24 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 25 May 2022 20:03:16 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/report/IssueFindingDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/report/RegulatoryReportMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/report/RegulatoryReportDaoTest.java

index b1fdfe9f761a3526f7c5213a75da73e4d4693d17..6881a90177c4e83ff41208b7d6a8eb90498c5955 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.db.report;
 
+import java.util.List;
 import java.util.Set;
 import javax.annotation.CheckForNull;
 import org.sonar.api.rules.RuleType;
@@ -40,6 +41,7 @@ public class IssueFindingDto {
   private String securityStandards;
   private boolean isNewCodeReferenceIssue;
   private long creationDate;
+  private List<String> comments;
 
   public String getStatus() {
     return status;
@@ -105,4 +107,8 @@ public class IssueFindingDto {
   public long getCreationDate() {
     return creationDate;
   }
+
+  public List<String> getComments() {
+    return comments;
+  }
 }
index c598bcc587c87939b548c26576a14c495e502c88..50111cac5369190a17a0095e4ba52bb1acecb794 100644 (file)
@@ -3,6 +3,13 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
 
 <mapper namespace="org.sonar.db.report.RegulatoryReportMapper">
+  <resultMap id="issueResultMap" type="org.sonar.db.report.IssueFindingDto" autoMapping="true">
+    <id property="kee" column="kee"/>
+    <collection property="comments" ofType="string">
+      <result column="change_data"/>
+    </collection>
+  </resultMap>
+
   <sql id="qualityGateFindingColumns">
     m.description as description,
     qgc.operator as operator,
@@ -43,6 +50,7 @@
     r.security_standards as securityStandards,
     r.name as ruleName,
     i.issue_creation_date as creationDate,
+
     <include refid="org.sonar.db.issue.IssueMapper.isNewCodeReferenceIssue"/>
   </sql>
 
     where oqp.uuid=#{qualityProfileUuid,jdbcType=VARCHAR}
   </select>
 
-  <select id="scrollIssues" parameterType="String" resultType="org.sonar.db.report.IssueFindingDto" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
+  <select id="scrollIssues" parameterType="String" resultMap="issueResultMap" resultOrdered="true" fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
     select
-    <include refid="issueColumns"/>
+    <include refid="issueColumns"/>,
+    ic.change_data,
+    ic.issue_change_creation_date
     from issues i
     inner join rules r on r.uuid=i.rule_uuid
     inner join components p on p.uuid=i.component_uuid
+    left join issue_changes ic on ic.issue_key = i.kee
     left join new_code_reference_issues n on i.kee = n.issue_key
     where i.project_uuid=#{branchUuid,jdbcType=VARCHAR}
+    and (ic.change_type = 'comment' or ic.change_type is null)
     and i.status !='CLOSED'
+    order by i.kee, ic.issue_change_creation_date
   </select>
 </mapper>
index fba4390d17a6d43164ec581fc6987ec5948327fe..e2e96733c50471b11a60bc71eda74c26c85c2a70 100644 (file)
@@ -28,10 +28,12 @@ import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.RuleType;
 import org.sonar.api.utils.System2;
+import org.sonar.core.util.UuidFactoryFast;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.issue.IssueChangeDto;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.metric.MetricDto;
 import org.sonar.db.project.ProjectDto;
@@ -165,6 +167,10 @@ public class RegulatoryReportDaoTest {
     IssueDto issue2 = db.issues().insertIssue(rule, project, file, i -> i.setStatus("CONFIRMED").setResolution(null));
     IssueDto issue3 = db.issues().insertIssue(rule, project, file, i -> i.setStatus("RESOLVED").setResolution(RESOLUTION_WONT_FIX));
 
+    // comments
+    db.issues().insertChange(issue1, ic -> ic.setChangeData("c2").setIssueChangeCreationDate(2000L).setChangeType("comment"));
+    db.issues().insertChange(issue1, ic -> ic.setChangeData("c1").setIssueChangeCreationDate(1000L).setChangeType("comment"));
+
     // not returned
     IssueDto issue4 = db.issues().insertIssue(rule, project, file, i -> i.setStatus("CLOSED").setResolution(null));
     ComponentDto otherProject = db.components().insertPrivateProject();
@@ -187,5 +193,6 @@ public class RegulatoryReportDaoTest {
     assertThat(issue.getType().getDbConstant()).isEqualTo(issue1.getType());
     assertThat(issue.getSecurityStandards()).isEqualTo(rule.getSecurityStandards());
     assertThat(issue.isManualSeverity()).isEqualTo(issue1.isManualSeverity());
+    assertThat(issue.getComments()).containsExactly("c1", "c2");
   }
 }