use of org.sonar.db.component.BranchType.BRANCH in project sonarqube by SonarSource.
the class ComponentDaoTest method selectPrivateProjectsWithNcloc.
@Test
public void selectPrivateProjectsWithNcloc() {
MetricDto metric = db.measures().insertMetric(m -> m.setKey("ncloc"));
// project1, not the biggest branch - not returned
final ComponentDto project1 = db.components().insertPrivateProject(b -> b.setName("foo"));
insertMeasure(20d, project1, metric);
// branch of project1 - returned
insertMeasure(30d, db.components().insertProjectBranch(project1, b -> b.setBranchType(BRANCH)), metric);
// project2 - returned
insertMeasure(10d, db.components().insertPrivateProject(b -> b.setName("bar")), metric);
// public project - not returned
insertMeasure(11d, db.components().insertPublicProject(b -> b.setName("other")), metric);
List<ProjectNclocDistributionDto> result = underTest.selectPrivateProjectsWithNcloc(db.getSession());
assertThat(result).extracting(ProjectNclocDistributionDto::getName).containsExactly("foo", "bar");
assertThat(result).extracting(ProjectNclocDistributionDto::getNcloc).containsExactly(30L, 10L);
}
use of org.sonar.db.component.BranchType.BRANCH in project sonarqube by SonarSource.
the class AsyncIssueIndexingImplTest method characteristics_are_defined.
@Test
public void characteristics_are_defined() {
BranchDto dto = new BranchDto().setBranchType(BRANCH).setKey("branch_1").setUuid("branch_uuid1").setProjectUuid("project_uuid1");
dbClient.branchDao().insert(dbTester.getSession(), dto);
dbTester.commit();
insertSnapshot("analysis_1", "project_uuid1", 1);
BranchDto dto2 = new BranchDto().setBranchType(PULL_REQUEST).setKey("pr_1").setUuid("pr_uuid_1").setProjectUuid("project_uuid2");
dbClient.branchDao().insert(dbTester.getSession(), dto2);
dbTester.commit();
insertSnapshot("analysis_2", "project_uuid2", 2);
underTest.triggerOnIndexCreation();
ArgumentCaptor<Collection<CeTaskSubmit>> captor = ArgumentCaptor.forClass(Collection.class);
verify(ceQueue, times(1)).massSubmit(captor.capture());
List<Collection<CeTaskSubmit>> captures = captor.getAllValues();
assertThat(captures).hasSize(1);
Collection<CeTaskSubmit> tasks = captures.get(0);
assertThat(tasks).hasSize(2);
assertThat(tasks).extracting(p -> p.getCharacteristics().get(BRANCH_TYPE_KEY), p -> p.getCharacteristics().get(CeTaskCharacteristicDto.BRANCH_KEY), p -> p.getCharacteristics().get(CeTaskCharacteristicDto.PULL_REQUEST)).containsExactlyInAnyOrder(tuple("BRANCH", "branch_1", null), tuple("PULL_REQUEST", null, "pr_1"));
}
use of org.sonar.db.component.BranchType.BRANCH in project sonarqube by SonarSource.
the class SearchEventsAction method computeQualityGateChangeEvents.
private Stream<Event> computeQualityGateChangeEvents(DbSession dbSession, Map<String, ComponentDto> projectsByUuid, Map<String, BranchDto> branchesByUuids, List<SnapshotDto> analyses) {
Map<String, EventDto> eventsByComponentUuid = new HashMap<>();
dbClient.eventDao().selectByAnalysisUuids(dbSession, analyses.stream().map(SnapshotDto::getUuid).collect(toList(analyses.size()))).stream().sorted(comparing(EventDto::getDate)).filter(e -> EventCategory.QUALITY_GATE.getLabel().equals(e.getCategory())).forEach(e -> eventsByComponentUuid.put(e.getComponentUuid(), e));
Predicate<EventDto> branchPredicate = e -> branchesByUuids.get(e.getComponentUuid()).getBranchType() == BRANCH;
return eventsByComponentUuid.values().stream().sorted(comparing(EventDto::getDate)).filter(branchPredicate).map(e -> {
BranchDto branch = branchesByUuids.get(e.getComponentUuid());
ComponentDto project = projectsByUuid.get(branch.getProjectUuid());
checkState(project != null, "Found event '%s', for a component that we did not search for", e.getUuid());
return Event.newBuilder().setCategory(EventCategory.fromLabel(e.getCategory()).name()).setProject(project.getKey()).setMessage(branch.isMain() ? format("Quality Gate status of project '%s' changed to '%s'", project.name(), e.getName()) : format("Quality Gate status of project '%s' on branch '%s' changed to '%s'", project.name(), branch.getKey(), e.getName())).setLink(computeDashboardLink(project, branch)).setDate(formatDateTime(e.getDate())).build();
});
}
use of org.sonar.db.component.BranchType.BRANCH in project sonarqube by SonarSource.
the class ListActionTest method status_on_branch.
@Test
public void status_on_branch() {
ComponentDto project = db.components().insertPrivateProject();
userSession.logIn().addProjectPermission(USER, project);
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.BRANCH));
db.measures().insertLiveMeasure(branch, qualityGateStatus, m -> m.setData("OK"));
ListWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWsResponse.class);
assertThat(response.getBranchesList()).extracting(b -> b.getStatus().hasQualityGateStatus(), b -> b.getStatus().getQualityGateStatus()).containsExactlyInAnyOrder(tuple(false, ""), tuple(true, "OK"));
}
use of org.sonar.db.component.BranchType.BRANCH in project sonarqube by SonarSource.
the class ListAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
String projectKey = request.mandatoryParam(PARAM_PROJECT);
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto projectOrApp = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);
checkPermission(projectOrApp);
Collection<BranchDto> branches = dbClient.branchDao().selectByProject(dbSession, projectOrApp).stream().filter(b -> b.getBranchType() == BRANCH).collect(toList());
List<String> branchUuids = branches.stream().map(BranchDto::getUuid).collect(toList());
Map<String, LiveMeasureDto> qualityGateMeasuresByComponentUuids = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricKeys(dbSession, branchUuids, singletonList(ALERT_STATUS_KEY)).stream().collect(uniqueIndex(LiveMeasureDto::getComponentUuid));
Map<String, String> analysisDateByBranchUuid = dbClient.snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, branchUuids).stream().collect(uniqueIndex(SnapshotDto::getComponentUuid, s -> formatDateTime(s.getCreatedAt())));
ProjectBranches.ListWsResponse.Builder protobufResponse = ProjectBranches.ListWsResponse.newBuilder();
branches.forEach(b -> addBranch(protobufResponse, b, qualityGateMeasuresByComponentUuids.get(b.getUuid()), analysisDateByBranchUuid.get(b.getUuid())));
WsUtils.writeProtobuf(protobufResponse.build(), request, response);
}
}
Aggregations