Search in sources :

Example 1 with PARAM_PULL_REQUEST

use of org.sonar.server.branch.pr.ws.PullRequestsWsParameters.PARAM_PULL_REQUEST 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();
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) NewController(org.sonar.api.server.ws.WebService.NewController) BranchDto(org.sonar.db.component.BranchDto) ComponentFinder(org.sonar.server.component.ComponentFinder) PARAM_PROJECT(org.sonar.server.branch.pr.ws.PullRequestsWsParameters.PARAM_PROJECT) PullRequestsWs.addPullRequestParam(org.sonar.server.branch.pr.ws.PullRequestsWs.addPullRequestParam) DbSession(org.sonar.db.DbSession) NotFoundException(org.sonar.server.exceptions.NotFoundException) PULL_REQUEST(org.sonar.db.component.BranchType.PULL_REQUEST) PARAM_PULL_REQUEST(org.sonar.server.branch.pr.ws.PullRequestsWsParameters.PARAM_PULL_REQUEST) Request(org.sonar.api.server.ws.Request) DbClient(org.sonar.db.DbClient) UserRole(org.sonar.api.web.UserRole) WebService(org.sonar.api.server.ws.WebService) PullRequestsWs.addProjectParam(org.sonar.server.branch.pr.ws.PullRequestsWs.addProjectParam) ACTION_DELETE(org.sonar.server.branch.ws.ProjectBranchesParameters.ACTION_DELETE) Response(org.sonar.api.server.ws.Response) ProjectDto(org.sonar.db.project.ProjectDto) UserSession(org.sonar.server.user.UserSession) ComponentCleanerService(org.sonar.server.component.ComponentCleanerService) DbSession(org.sonar.db.DbSession) BranchDto(org.sonar.db.component.BranchDto) NotFoundException(org.sonar.server.exceptions.NotFoundException)

Aggregations

Request (org.sonar.api.server.ws.Request)1 Response (org.sonar.api.server.ws.Response)1 WebService (org.sonar.api.server.ws.WebService)1 NewController (org.sonar.api.server.ws.WebService.NewController)1 UserRole (org.sonar.api.web.UserRole)1 DbClient (org.sonar.db.DbClient)1 DbSession (org.sonar.db.DbSession)1 BranchDto (org.sonar.db.component.BranchDto)1 PULL_REQUEST (org.sonar.db.component.BranchType.PULL_REQUEST)1 ProjectDto (org.sonar.db.project.ProjectDto)1 PullRequestsWs.addProjectParam (org.sonar.server.branch.pr.ws.PullRequestsWs.addProjectParam)1 PullRequestsWs.addPullRequestParam (org.sonar.server.branch.pr.ws.PullRequestsWs.addPullRequestParam)1 PARAM_PROJECT (org.sonar.server.branch.pr.ws.PullRequestsWsParameters.PARAM_PROJECT)1 PARAM_PULL_REQUEST (org.sonar.server.branch.pr.ws.PullRequestsWsParameters.PARAM_PULL_REQUEST)1 ACTION_DELETE (org.sonar.server.branch.ws.ProjectBranchesParameters.ACTION_DELETE)1 ComponentCleanerService (org.sonar.server.component.ComponentCleanerService)1 ComponentFinder (org.sonar.server.component.ComponentFinder)1 NotFoundException (org.sonar.server.exceptions.NotFoundException)1 UserSession (org.sonar.server.user.UserSession)1