use of org.sonarqube.ws.AlmSettings.GetBindingWsResponse in project sonarqube by SonarSource.
the class GetBindingAction method handle.
@Override
public void handle(Request request, Response response) {
GetBindingWsResponse wsResponse = doHandle(request);
writeProtobuf(wsResponse, request, response);
}
use of org.sonarqube.ws.AlmSettings.GetBindingWsResponse in project sonarqube by SonarSource.
the class GetBindingAction method doHandle.
private GetBindingWsResponse doHandle(Request request) {
String projectKey = request.mandatoryParam(PARAM_PROJECT);
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
userSession.checkProjectPermission(ADMIN, project);
ProjectAlmSettingDto projectAlmSetting = dbClient.projectAlmSettingDao().selectByProject(dbSession, project).orElseThrow(() -> new NotFoundException(format("Project '%s' is not bound to any ALM", project.getKey())));
AlmSettingDto almSetting = dbClient.almSettingDao().selectByUuid(dbSession, projectAlmSetting.getAlmSettingUuid()).orElseThrow(() -> new IllegalStateException(format("ALM setting with uuid '%s' cannot be found", projectAlmSetting.getAlmSettingUuid())));
GetBindingWsResponse.Builder builder = GetBindingWsResponse.newBuilder().setAlm(toAlmWs(almSetting.getAlm())).setKey(almSetting.getKey());
ofNullable(projectAlmSetting.getAlmRepo()).ifPresent(builder::setRepository);
ofNullable(almSetting.getUrl()).ifPresent(builder::setUrl);
ofNullable(projectAlmSetting.getAlmSlug()).ifPresent(builder::setSlug);
ofNullable(projectAlmSetting.getSummaryCommentEnabled()).ifPresent(builder::setSummaryCommentEnabled);
ofNullable(projectAlmSetting.getMonorepo()).ifPresent(builder::setMonorepo);
return builder.build();
}
}
use of org.sonarqube.ws.AlmSettings.GetBindingWsResponse in project sonarqube by SonarSource.
the class GetBindingActionTest method get_azure_project_binding.
@Test
public void get_azure_project_binding() {
userSession.logIn(user).addProjectPermission(ADMIN, project);
AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting();
ProjectAlmSettingDto projectAlmSettingDto = db.almSettings().insertAzureMonoRepoProjectAlmSetting(almSetting, project);
GetBindingWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(GetBindingWsResponse.class);
assertThat(response.getAlm()).isEqualTo(AlmSettings.Alm.azure);
assertThat(response.getKey()).isEqualTo(almSetting.getKey());
assertThat(response.getUrl()).isEqualTo(almSetting.getUrl());
assertThat(response.getRepository()).isEqualTo(projectAlmSettingDto.getAlmRepo());
assertThat(response.getSlug()).isEqualTo(projectAlmSettingDto.getAlmSlug());
assertThat(response.hasSummaryCommentEnabled()).isFalse();
assertThat(response.getMonorepo()).isTrue();
}
use of org.sonarqube.ws.AlmSettings.GetBindingWsResponse in project sonarqube by SonarSource.
the class GetBindingActionTest method get_gitlab_project_binding.
@Test
public void get_gitlab_project_binding() {
UserDto user = db.users().insertUser();
ProjectDto project = db.components().insertPrivateProjectDto();
userSession.logIn(user).addProjectPermission(ADMIN, project);
AlmSettingDto almSetting = db.almSettings().insertGitlabAlmSetting();
db.almSettings().insertGitlabProjectAlmSetting(almSetting, project);
GetBindingWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(GetBindingWsResponse.class);
assertThat(response.getAlm()).isEqualTo(AlmSettings.Alm.gitlab);
assertThat(response.getKey()).isEqualTo(almSetting.getKey());
assertThat(response.hasRepository()).isFalse();
assertThat(response.getUrl()).isEqualTo(almSetting.getUrl());
assertThat(response.hasUrl()).isTrue();
assertThat(response.hasSummaryCommentEnabled()).isFalse();
}
use of org.sonarqube.ws.AlmSettings.GetBindingWsResponse in project sonarqube by SonarSource.
the class GetBindingActionTest method get_github_project_binding.
@Test
public void get_github_project_binding() {
userSession.logIn(user).addProjectPermission(ADMIN, project);
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
ProjectAlmSettingDto githubProjectAlmSetting = db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project);
GetBindingWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(GetBindingWsResponse.class);
assertThat(response.getAlm()).isEqualTo(AlmSettings.Alm.github);
assertThat(response.getKey()).isEqualTo(githubAlmSetting.getKey());
assertThat(response.getRepository()).isEqualTo(githubProjectAlmSetting.getAlmRepo());
assertThat(response.getUrl()).isEqualTo(githubAlmSetting.getUrl());
assertThat(response.getSummaryCommentEnabled()).isTrue();
}
Aggregations