use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class SearchEventsAction method computeNewIssuesEvents.
private Stream<Event> computeNewIssuesEvents(Map<String, ComponentDto> projectsByUuid, Map<String, BranchDto> branchesByUuids, List<UuidFromPair> uuidFromPairs) {
Map<String, Long> fromsByProjectUuid = uuidFromPairs.stream().collect(Collectors.toMap(UuidFromPair::getComponentUuid, UuidFromPair::getFrom));
List<ProjectStatistics> projectStatistics = issueIndex.searchProjectStatistics(componentUuids(uuidFromPairs), fromDates(uuidFromPairs), userSession.getUuid());
return projectStatistics.stream().map(e -> {
BranchDto branch = branchesByUuids.get(e.getProjectUuid());
ComponentDto project = projectsByUuid.get(branch.getProjectUuid());
long issueCount = e.getIssueCount();
long lastIssueDate = e.getLastIssueDate();
String branchType = branch.getBranchType().equals(PULL_REQUEST) ? "pull request" : "branch";
return Event.newBuilder().setCategory("NEW_ISSUES").setMessage(format("You have %s new %s on project '%s'", issueCount, issueCount == 1 ? "issue" : "issues", project.name()) + (branch.isMain() ? "" : format(" on %s '%s'", branchType, branch.getKey()))).setLink(computeIssuesSearchLink(project, branch, fromsByProjectUuid.get(project.uuid()), userSession.getLogin())).setProject(project.getKey()).setDate(formatDateTime(lastIssueDate)).build();
});
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class SearchEventsAction method computeEvents.
private Stream<Event> computeEvents(Request request) {
List<String> projectKeys = request.mandatoryParamAsStrings(PARAM_PROJECTS);
List<Long> fromDates = mandatoryParamAsDateTimes(request, PARAM_FROM);
if (projectKeys.isEmpty()) {
return Stream.empty();
}
try (DbSession dbSession = dbClient.openSession(false)) {
List<ComponentDto> authorizedProjects = searchProjects(dbSession, projectKeys);
Map<String, ComponentDto> componentsByUuid = authorizedProjects.stream().collect(uniqueIndex(ComponentDto::uuid));
List<UuidFromPair> uuidFromPairs = componentUuidFromPairs(fromDates, projectKeys, authorizedProjects);
List<SnapshotDto> analyses = dbClient.snapshotDao().selectFinishedByComponentUuidsAndFromDates(dbSession, componentUuids(uuidFromPairs), fromDates(uuidFromPairs));
if (analyses.isEmpty()) {
return Stream.empty();
}
List<String> projectUuids = analyses.stream().map(SnapshotDto::getComponentUuid).collect(toList());
Map<String, BranchDto> branchesByUuids = dbClient.branchDao().selectByUuids(dbSession, projectUuids).stream().collect(uniqueIndex(BranchDto::getUuid));
return Stream.concat(computeQualityGateChangeEvents(dbSession, componentsByUuid, branchesByUuids, analyses), computeNewIssuesEvents(componentsByUuid, branchesByUuids, uuidFromPairs));
}
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class ProjectStatusAction method getProjectThenSnapshot.
private ProjectAndSnapshot getProjectThenSnapshot(DbSession dbSession, @Nullable String projectUuid, @Nullable String projectKey, @Nullable String branchKey, @Nullable String pullRequestId) {
ProjectDto projectDto;
BranchDto branchDto;
if (projectUuid != null) {
projectDto = componentFinder.getProjectByUuid(dbSession, projectUuid);
branchDto = componentFinder.getMainBranch(dbSession, projectDto);
} else {
projectDto = componentFinder.getProjectByKey(dbSession, projectKey);
branchDto = componentFinder.getBranchOrPullRequest(dbSession, projectDto, branchKey, pullRequestId);
}
Optional<SnapshotDto> snapshot = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(dbSession, branchDto.getUuid());
return new ProjectAndSnapshot(projectDto, branchDto, snapshot.orElse(null));
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class BranchSupportTest method createBranchComponent_delegates_to_delegate.
@Test
public void createBranchComponent_delegates_to_delegate() {
DbSession dbSession = mock(DbSession.class);
ComponentKey componentKey = mock(ComponentKey.class);
ComponentDto mainComponentDto = new ComponentDto();
ComponentDto expected = new ComponentDto();
BranchDto mainComponentBranchDto = new BranchDto();
when(branchSupportDelegate.createBranchComponent(dbSession, componentKey, mainComponentDto, mainComponentBranchDto)).thenReturn(expected);
ComponentDto dto = underTestWithBranch.createBranchComponent(dbSession, componentKey, mainComponentDto, mainComponentBranchDto);
assertThat(dto).isSameAs(expected);
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class ImportGithubProjectActionTest method import_project.
@Test
public void import_project() {
AlmSettingDto githubAlmSetting = setupAlm();
db.almPats().insert(p -> p.setAlmSettingUuid(githubAlmSetting.getUuid()).setUserUuid(userSession.getUuid()));
GithubApplicationClient.Repository repository = new GithubApplicationClient.Repository(1L, "Hello-World", false, "octocat/Hello-World", "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World", "default-branch");
when(appClient.getRepository(any(), any(), any(), any())).thenReturn(Optional.of(repository));
Projects.CreateWsResponse response = ws.newRequest().setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()).setParam(PARAM_ORGANIZATION, "octocat").setParam(PARAM_REPOSITORY_KEY, "octocat/Hello-World").executeProtobuf(Projects.CreateWsResponse.class);
Projects.CreateWsResponse.Project result = response.getProject();
assertThat(result.getKey()).isEqualTo(repository.getFullName().replace("/", "_"));
assertThat(result.getName()).isEqualTo(repository.getName());
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
assertThat(projectDto).isPresent();
assertThat(db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), projectDto.get())).isPresent();
Optional<BranchDto> mainBranch = db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get()).stream().filter(BranchDto::isMain).findAny();
assertThat(mainBranch).isPresent();
assertThat(mainBranch.get().getKey()).isEqualTo("default-branch");
}
Aggregations