use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class WebhookQGChangeEventListenerTest method onIssueChangesCallsWebhookOnBranch.
public void onIssueChangesCallsWebhookOnBranch(BranchType branchType) {
ProjectAndBranch nonMainBranch = insertBranch(branchType, "foo");
SnapshotDto analysis = insertAnalysisTask(nonMainBranch);
Configuration configuration = mock(Configuration.class);
QGChangeEvent qualityGateEvent = newQGChangeEvent(nonMainBranch, analysis, configuration, null);
mockWebhookEnabled(qualityGateEvent.getProject());
underTest.onIssueChanges(qualityGateEvent, CHANGED_ISSUES_ARE_IGNORED);
verifyWebhookCalled(nonMainBranch, analysis, qualityGateEvent.getProject());
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class IssueQueryFactory method setCreatedAfterFromRequest.
private void setCreatedAfterFromRequest(DbSession dbSession, IssueQuery.Builder builder, SearchRequest request, List<ComponentDto> componentUuids, ZoneId timeZone) {
Date createdAfter = parseStartingDateOrDateTime(request.getCreatedAfter(), timeZone);
String createdInLast = request.getCreatedInLast();
if (notInNewCodePeriod(request)) {
checkArgument(createdAfter == null || createdInLast == null, format("Parameters %s and %s cannot be set simultaneously", PARAM_CREATED_AFTER, PARAM_CREATED_IN_LAST));
setCreatedAfterFromDates(builder, createdAfter, createdInLast, true);
} else {
// If the filter is on leak period
checkArgument(createdAfter == null, "Parameters '%s' and '%s' or '%s' cannot be set simultaneously", PARAM_CREATED_AFTER, PARAM_IN_NEW_CODE_PERIOD, PARAM_SINCE_LEAK_PERIOD);
checkArgument(createdInLast == null, format("Parameters '%s' and '%s' or '%s' cannot be set simultaneously", PARAM_CREATED_IN_LAST, PARAM_IN_NEW_CODE_PERIOD, PARAM_SINCE_LEAK_PERIOD));
checkArgument(componentUuids.size() == 1, "One and only one component must be provided when searching in new code period");
ComponentDto component = componentUuids.iterator().next();
if (!QUALIFIERS_WITHOUT_LEAK_PERIOD.contains(component.qualifier()) && request.getPullRequest() == null) {
Optional<SnapshotDto> snapshot = getLastAnalysis(dbSession, component);
boolean isLastAnalysisUsingReferenceBranch = isLastAnalysisUsingReferenceBranch(snapshot);
if (isLastAnalysisUsingReferenceBranch) {
builder.newCodeOnReference(true);
} else {
// if last analysis has no period date, then no issue should be considered new.
Date createdAfterFromSnapshot = findCreatedAfterFromComponentUuid(snapshot);
setCreatedAfterFromDates(builder, createdAfterFromSnapshot, null, false);
}
}
}
}
use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.
the class ShowAction method doHandle.
private ShowWsResponse doHandle(Request request) {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto component = loadComponent(dbSession, request);
userSession.checkComponentPermission(UserRole.USER, component);
Optional<SnapshotDto> lastAnalysis = dbClient.snapshotDao().selectLastAnalysisByComponentUuid(dbSession, component.projectUuid());
List<ComponentDto> ancestors = dbClient.componentDao().selectAncestors(dbSession, component);
return buildResponse(dbSession, component, ancestors, lastAnalysis.orElse(null));
}
}
use of org.sonar.db.component.SnapshotDto 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.SnapshotDto in project sonarqube by SonarSource.
the class SetAction method getAnalysis.
private SnapshotDto getAnalysis(DbSession dbSession, String analysisUuid, ProjectDto project, BranchDto branch) {
SnapshotDto snapshotDto = dbClient.snapshotDao().selectByUuid(dbSession, analysisUuid).orElseThrow(() -> new NotFoundException(format("Analysis '%s' is not found", analysisUuid)));
checkAnalysis(dbSession, project, branch, snapshotDto);
return snapshotDto;
}
Aggregations