Search in sources :

Example 1 with GetBindingWsResponse

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);
}
Also used : GetBindingWsResponse(org.sonarqube.ws.AlmSettings.GetBindingWsResponse)

Example 2 with GetBindingWsResponse

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();
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) DbSession(org.sonar.db.DbSession) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) GetBindingWsResponse(org.sonarqube.ws.AlmSettings.GetBindingWsResponse) NotFoundException(org.sonar.server.exceptions.NotFoundException) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto)

Example 3 with GetBindingWsResponse

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();
}
Also used : ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) GetBindingWsResponse(org.sonarqube.ws.AlmSettings.GetBindingWsResponse) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) Test(org.junit.Test)

Example 4 with GetBindingWsResponse

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();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) GetBindingWsResponse(org.sonarqube.ws.AlmSettings.GetBindingWsResponse) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) Test(org.junit.Test)

Example 5 with GetBindingWsResponse

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();
}
Also used : ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) GetBindingWsResponse(org.sonarqube.ws.AlmSettings.GetBindingWsResponse) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) Test(org.junit.Test)

Aggregations

GetBindingWsResponse (org.sonarqube.ws.AlmSettings.GetBindingWsResponse)6 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)5 ProjectAlmSettingDto (org.sonar.db.alm.setting.ProjectAlmSettingDto)5 Test (org.junit.Test)4 ProjectDto (org.sonar.db.project.ProjectDto)2 DbSession (org.sonar.db.DbSession)1 UserDto (org.sonar.db.user.UserDto)1 NotFoundException (org.sonar.server.exceptions.NotFoundException)1