use of org.sonar.server.branch.pr.ws.PullRequestsWsParameters.PARAM_PROJECT 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 project = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);
checkPermission(project);
List<BranchDto> pullRequests = dbClient.branchDao().selectByProject(dbSession, project).stream().filter(b -> b.getBranchType() == PULL_REQUEST).collect(toList());
List<String> pullRequestUuids = pullRequests.stream().map(BranchDto::getUuid).collect(toList());
Map<String, BranchDto> mergeBranchesByUuid = dbClient.branchDao().selectByUuids(dbSession, pullRequests.stream().map(BranchDto::getMergeBranchUuid).filter(Objects::nonNull).collect(toList())).stream().collect(uniqueIndex(BranchDto::getUuid));
Map<String, PrStatistics> branchStatisticsByBranchUuid = issueIndex.searchBranchStatistics(project.getUuid(), pullRequestUuids).stream().collect(uniqueIndex(PrStatistics::getBranchUuid, Function.identity()));
Map<String, LiveMeasureDto> qualityGateMeasuresByComponentUuids = dbClient.liveMeasureDao().selectByComponentUuidsAndMetricKeys(dbSession, pullRequestUuids, singletonList(ALERT_STATUS_KEY)).stream().collect(uniqueIndex(LiveMeasureDto::getComponentUuid));
Map<String, String> analysisDateByBranchUuid = dbClient.snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, pullRequestUuids).stream().collect(uniqueIndex(SnapshotDto::getComponentUuid, s -> formatDateTime(s.getCreatedAt())));
ProjectPullRequests.ListWsResponse.Builder protobufResponse = ProjectPullRequests.ListWsResponse.newBuilder();
pullRequests.forEach(b -> addPullRequest(protobufResponse, b, mergeBranchesByUuid, qualityGateMeasuresByComponentUuids.get(b.getUuid()), branchStatisticsByBranchUuid.get(b.getUuid()), analysisDateByBranchUuid.get(b.getUuid())));
writeProtobuf(protobufResponse.build(), request, response);
}
}
use of org.sonar.server.branch.pr.ws.PullRequestsWsParameters.PARAM_PROJECT in project sonarqube by SonarSource.
the class DeleteAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
String projectKey = request.mandatoryParam(PARAM_PROJECT);
String pullRequestId = request.mandatoryParam(PARAM_PULL_REQUEST);
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto project = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);
checkPermission(project);
BranchDto pullRequest = dbClient.branchDao().selectByPullRequestKey(dbSession, project.getUuid(), pullRequestId).filter(branch -> branch.getBranchType() == PULL_REQUEST).orElseThrow(() -> new NotFoundException(String.format("Pull request '%s' is not found for project '%s'", pullRequestId, projectKey)));
componentCleanerService.deleteBranch(dbSession, pullRequest);
response.noContent();
}
}
Aggregations