use of org.sonarqube.ws.Developers.SearchEventsWsResponse.Event 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.sonarqube.ws.Developers.SearchEventsWsResponse.Event in project sonarqube by SonarSource.
the class SearchEventsActionTest method events.
@Test
public void events() {
userSession.logIn().setRoot();
when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project);
SnapshotDto projectAnalysis = insertAnalysis(project, 1_500_000_000_000L);
db.events().insertEvent(newQualityGateEvent(projectAnalysis).setDate(projectAnalysis.getCreatedAt()).setName("Passed"));
insertIssue(project, projectAnalysis);
insertIssue(project, projectAnalysis);
SnapshotDto branchAnalysis = insertAnalysis(branch, 1_501_000_000_000L);
db.events().insertEvent(newQualityGateEvent(branchAnalysis).setDate(branchAnalysis.getCreatedAt()).setName("Failed"));
insertIssue(branch, branchAnalysis);
issueIndexer.indexAllIssues();
SearchEventsWsResponse result = ws.newRequest().setParam(PARAM_PROJECTS, project.getKey()).setParam(PARAM_FROM, formatDateTime(1_499_000_000_000L)).executeProtobuf(SearchEventsWsResponse.class);
assertThat(result.getEventsList()).extracting(Event::getCategory, Event::getProject, Event::getMessage).containsOnly(tuple("QUALITY_GATE", project.getKey(), format("Quality Gate status of project '%s' changed to 'Passed'", project.name())), tuple("QUALITY_GATE", project.getKey(), format("Quality Gate status of project '%s' on branch '%s' changed to 'Failed'", project.name(), branch.getBranch())), tuple("NEW_ISSUES", project.getKey(), format("You have 2 new issues on project '%s'", project.name())), tuple("NEW_ISSUES", project.getKey(), format("You have 1 new issue on project '%s' on branch '%s'", project.name(), branch.getBranch())));
verify(issueIndexSyncProgressChecker).checkIfAnyComponentsNeedIssueSync(any(), argThat(arg -> arg.contains(project.getKey())));
}
Aggregations