import org.sonar.core.util.Uuids;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
-import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.dialect.Dialect;
* If Main Branch = 100 LOCs and the "largest branch" is 80 LOCs, I'm expecting to consider the value 100.
*/
public long sumNclocOfBiggestBranch(DbSession dbSession, SumNclocDbQuery dbQuery) {
- Long ncloc = mapper(dbSession).sumNclocOfBiggestBranch(
- NCLOC_KEY, BranchType.BRANCH, dbQuery.getOnlyPrivateProjects(), dbQuery.getProjectUuidToExclude());
+ Long ncloc = mapper(dbSession).sumNclocOfBiggestBranch(NCLOC_KEY, dbQuery.getOnlyPrivateProjects(), dbQuery.getProjectUuidToExclude());
return ncloc == null ? 0L : ncloc;
}
import javax.annotation.Nullable;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.ResultHandler;
-import org.sonar.db.component.BranchType;
public interface LiveMeasureMapper {
Long sumNclocOfBiggestBranch(
@Param("ncloc") String nclocKey,
- @Param("branchType") BranchType branchType,
@Param("private") Boolean privateProject,
@Nullable @Param("projectUuidToExclude") String projectUuidToExclude);
select b.project_uuid as projectUuid, max(lm.value) as maxncloc
from live_measures lm
inner join metrics m on m.uuid = lm.metric_uuid
- inner join project_branches b on b.uuid = lm.component_uuid and b.branch_type = #{branchType, jdbcType=VARCHAR}
+ inner join project_branches b on b.uuid = lm.component_uuid
inner join projects p on p.uuid = b.project_uuid and p.qualifier = 'TRK'
<where>
m.name = #{ncloc, jdbcType=VARCHAR}
}
@Test
- public void take_largest_branches() {
+ public void take_largest_branch() {
server.setId("AU-TpxcB-iU5OvuD2FL7").setVersion("7.5.4");
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey(NCLOC_KEY));
ComponentDto project = db.components().insertPublicProject();
ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST));
db.measures().insertLiveMeasure(project, ncloc, m -> m.setValue(10d));
db.measures().insertLiveMeasure(branch1, ncloc, m -> m.setValue(20d));
- db.measures().insertLiveMeasure(pr, ncloc, m -> m.setValue(30d));
+ db.measures().insertLiveMeasure(pr, ncloc, m -> m.setValue(15d));
projectMeasuresIndexer.indexAll();
TelemetryData data = communityUnderTest.load();
assertThat(data.getNcloc()).isEqualTo(20L);
}
+ @Test
+ public void take_largest_branch_with_pr() {
+ server.setId("AU-TpxcB-iU5OvuD2FL7").setVersion("7.5.4");
+ MetricDto ncloc = db.measures().insertMetric(m -> m.setKey(NCLOC_KEY));
+ ComponentDto project = db.components().insertPublicProject();
+ ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
+ ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST));
+ db.measures().insertLiveMeasure(project, ncloc, m -> m.setValue(10d));
+ db.measures().insertLiveMeasure(branch1, ncloc, m -> m.setValue(20d));
+ db.measures().insertLiveMeasure(pr, ncloc, m -> m.setValue(30d));
+ projectMeasuresIndexer.indexAll();
+
+ TelemetryData data = communityUnderTest.load();
+
+ assertThat(data.getNcloc()).isEqualTo(30L);
+ }
+
@Test
public void data_contains_no_license_type_on_community_edition() {
TelemetryData data = communityUnderTest.load();