use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class TagsAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
try (DbSession dbSession = dbClient.openSession(false)) {
String projectKey = request.param(PARAM_PROJECT);
String branchKey = request.param(PARAM_BRANCH);
boolean all = request.mandatoryParamAsBoolean(PARAM_ALL);
checkIfAnyComponentsNeedIssueSync(dbSession, projectKey);
Optional<ComponentDto> project = getProject(dbSession, projectKey);
Optional<BranchDto> branch = project.flatMap(p -> dbClient.branchDao().selectByBranchKey(dbSession, p.uuid(), branchKey));
List<String> tags = searchTags(project.orElse(null), branch.orElse(null), request, all);
Issues.TagsResponse.Builder tagsResponseBuilder = Issues.TagsResponse.newBuilder();
tags.forEach(tagsResponseBuilder::addTags);
writeProtobuf(tagsResponseBuilder.build(), request, response);
}
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class SetBaselineAction method doHandle.
private void doHandle(Request request) {
String projectKey = request.mandatoryParam(PARAM_PROJECT);
String branchKey = trimToNull(request.param(PARAM_BRANCH));
String analysisUuid = request.mandatoryParam(PARAM_ANALYSIS);
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
BranchDto branch = loadBranch(dbSession, project, branchKey);
SnapshotDto analysis = getAnalysis(dbSession, analysisUuid);
checkRequest(project, branch, analysis, branchKey);
dbClient.newCodePeriodDao().upsert(dbSession, new NewCodePeriodDto().setProjectUuid(project.getUuid()).setBranchUuid(branch.getUuid()).setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue(analysisUuid));
dbSession.commit();
}
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class UnsetBaselineAction method doHandle.
private void doHandle(Request request) {
String projectKey = request.mandatoryParam(PARAM_PROJECT);
String branchKey = trimToNull(request.param(PARAM_BRANCH));
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
userSession.checkProjectPermission(UserRole.ADMIN, project);
BranchDto branch = loadBranch(dbSession, project, branchKey);
dbClient.newCodePeriodDao().delete(dbSession, project.getUuid(), branch.getUuid());
dbSession.commit();
}
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class ProjectStatusAction method getSnapshotThenProject.
private ProjectAndSnapshot getSnapshotThenProject(DbSession dbSession, String analysisUuid) {
SnapshotDto snapshotDto = getSnapshot(dbSession, analysisUuid);
BranchDto branchDto = dbClient.branchDao().selectByUuid(dbSession, snapshotDto.getComponentUuid()).orElseThrow(() -> new IllegalStateException(String.format("Branch '%s' not found", snapshotDto.getUuid())));
ProjectDto projectDto = dbClient.projectDao().selectByUuid(dbSession, branchDto.getProjectUuid()).orElseThrow(() -> new IllegalStateException(String.format("Project '%s' not found", branchDto.getProjectUuid())));
return new ProjectAndSnapshot(projectDto, branchDto, snapshotDto);
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class ImportBitbucketCloudRepoActionTest method import_project.
@Test
public void import_project() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertBitbucketCloudAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
});
Repository repo = getGsonBBCRepo();
when(bitbucketCloudRestClient.getRepo(any(), any(), any())).thenReturn(repo);
Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("repositorySlug", "repo-slug-1").executeProtobuf(Projects.CreateWsResponse.class);
Projects.CreateWsResponse.Project result = response.getProject();
assertThat(result.getKey()).isEqualTo(almSetting.getAppId() + "_" + repo.getSlug());
assertThat(result.getName()).isEqualTo(repo.getName());
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
assertThat(projectDto).isPresent();
Optional<ProjectAlmSettingDto> projectAlmSettingDto = db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), projectDto.get());
assertThat(projectAlmSettingDto).isPresent();
assertThat(projectAlmSettingDto.get().getAlmRepo()).isEqualTo("repo-slug-1");
Optional<BranchDto> branchDto = db.getDbClient().branchDao().selectByBranchKey(db.getSession(), projectDto.get().getUuid(), "develop");
assertThat(branchDto).isPresent();
assertThat(branchDto.get().isMain()).isTrue();
}
Aggregations