use of org.sonar.server.branch.ws.ProjectBranchesParameters.PARAM_NAME in project sonarqube by SonarSource.
the class RenameAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
String projectKey = request.mandatoryParam(PARAM_PROJECT);
String newBranchName = request.mandatoryParam(PARAM_NAME);
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto project = componentFinder.getProjectOrApplicationByKey(dbSession, projectKey);
checkPermission(project);
Optional<BranchDto> existingBranch = dbClient.branchDao().selectByBranchKey(dbSession, project.getUuid(), newBranchName);
checkArgument(!existingBranch.filter(b -> !b.isMain()).isPresent(), "Impossible to update branch name: a branch with name \"%s\" already exists in the project.", newBranchName);
dbClient.branchDao().updateMainBranchName(dbSession, project.getUuid(), newBranchName);
dbSession.commit();
response.noContent();
}
}
Aggregations