*/
package org.sonar.db.report;
+import java.util.List;
import java.util.Set;
import javax.annotation.CheckForNull;
import org.sonar.api.rules.RuleType;
private String securityStandards;
private boolean isNewCodeReferenceIssue;
private long creationDate;
+ private List<String> comments;
public String getStatus() {
return status;
public long getCreationDate() {
return creationDate;
}
+
+ public List<String> getComments() {
+ return comments;
+ }
}
<!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,
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>
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;
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();
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");
}
}