Search in sources :

Example 1 with ListBitbucketserverProjectsWsResponse

use of org.sonarqube.ws.AlmIntegrations.ListBitbucketserverProjectsWsResponse in project sonarqube by SonarSource.

the class ListBitbucketServerProjectsAction method handle.

@Override
public void handle(Request request, Response response) {
    ListBitbucketserverProjectsWsResponse wsResponse = doHandle(request);
    writeProtobuf(wsResponse, request, response);
}
Also used : ListBitbucketserverProjectsWsResponse(org.sonarqube.ws.AlmIntegrations.ListBitbucketserverProjectsWsResponse)

Example 2 with ListBitbucketserverProjectsWsResponse

use of org.sonarqube.ws.AlmIntegrations.ListBitbucketserverProjectsWsResponse in project sonarqube by SonarSource.

the class ListBitbucketServerProjectsActionTest method list_projects.

@Test
public void list_projects() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).addPermission(PROVISION_PROJECTS);
    AlmSettingDto almSetting = db.almSettings().insertGitHubAlmSetting();
    db.almPats().insert(dto -> {
        dto.setAlmSettingUuid(almSetting.getUuid());
        dto.setUserUuid(user.getUuid());
    });
    ListBitbucketserverProjectsWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(ListBitbucketserverProjectsWsResponse.class);
    assertThat(response.getProjectsCount()).isOne();
    assertThat(response.getProjectsList()).extracting(AlmIntegrations.AlmProject::getKey, AlmIntegrations.AlmProject::getName).containsExactly(tuple("key", "name"));
}
Also used : UserDto(org.sonar.db.user.UserDto) ListBitbucketserverProjectsWsResponse(org.sonarqube.ws.AlmIntegrations.ListBitbucketserverProjectsWsResponse) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) AlmIntegrations(org.sonarqube.ws.AlmIntegrations) Test(org.junit.Test)

Example 3 with ListBitbucketserverProjectsWsResponse

use of org.sonarqube.ws.AlmIntegrations.ListBitbucketserverProjectsWsResponse in project sonarqube by SonarSource.

the class ListBitbucketServerProjectsAction method doHandle.

private ListBitbucketserverProjectsWsResponse doHandle(Request request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        userSession.checkLoggedIn().checkPermission(PROVISION_PROJECTS);
        String almSettingKey = request.mandatoryParam(PARAM_ALM_SETTING);
        String userUuid = requireNonNull(userSession.getUuid(), "User UUID is not null");
        AlmSettingDto almSettingDto = dbClient.almSettingDao().selectByKey(dbSession, almSettingKey).orElseThrow(() -> new NotFoundException(String.format("ALM Setting '%s' not found", almSettingKey)));
        Optional<AlmPatDto> almPatDto = dbClient.almPatDao().selectByUserAndAlmSetting(dbSession, userUuid, almSettingDto);
        String pat = almPatDto.map(AlmPatDto::getPersonalAccessToken).orElseThrow(() -> new IllegalArgumentException("No personal access token found"));
        String url = requireNonNull(almSettingDto.getUrl(), "URL cannot be null");
        ProjectList projectList = bitbucketServerRestClient.getProjects(url, pat);
        List<AlmProject> values = projectList.getValues().stream().map(ListBitbucketServerProjectsAction::toAlmProject).collect(Collectors.toList());
        ListBitbucketserverProjectsWsResponse.Builder builder = ListBitbucketserverProjectsWsResponse.newBuilder().addAllProjects(values);
        return builder.build();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ProjectList(org.sonar.alm.client.bitbucketserver.ProjectList) AlmPatDto(org.sonar.db.alm.pat.AlmPatDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) AlmProject(org.sonarqube.ws.AlmIntegrations.AlmProject) ListBitbucketserverProjectsWsResponse(org.sonarqube.ws.AlmIntegrations.ListBitbucketserverProjectsWsResponse) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto)

Aggregations

ListBitbucketserverProjectsWsResponse (org.sonarqube.ws.AlmIntegrations.ListBitbucketserverProjectsWsResponse)3 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)2 Test (org.junit.Test)1 ProjectList (org.sonar.alm.client.bitbucketserver.ProjectList)1 DbSession (org.sonar.db.DbSession)1 AlmPatDto (org.sonar.db.alm.pat.AlmPatDto)1 UserDto (org.sonar.db.user.UserDto)1 NotFoundException (org.sonar.server.exceptions.NotFoundException)1 AlmIntegrations (org.sonarqube.ws.AlmIntegrations)1 AlmProject (org.sonarqube.ws.AlmIntegrations.AlmProject)1