use of org.sonar.alm.client.bitbucketserver.RepositoryList in project sonarqube by SonarSource.
the class SearchBitbucketServerReposActionTest method before.
@Before
public void before() {
RepositoryList gsonBBSRepoList = new RepositoryList();
gsonBBSRepoList.setLastPage(true);
List<Repository> values = new ArrayList<>();
values.add(getGsonBBSRepo1());
values.add(getGsonBBSRepo2());
gsonBBSRepoList.setValues(values);
when(bitbucketServerRestClient.getRepos(any(), any(), any(), any())).thenReturn(gsonBBSRepoList);
}
use of org.sonar.alm.client.bitbucketserver.RepositoryList in project sonarqube by SonarSource.
the class SearchBitbucketServerReposAction method doHandle.
private SearchBitbucketserverReposWsResponse 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 cannot be 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 projectKey = request.param(PARAM_PROJECT_NAME);
String repoName = request.param(PARAM_REPO_NAME);
String pat = almPatDto.map(AlmPatDto::getPersonalAccessToken).orElseThrow(() -> new IllegalArgumentException("No personal access token found"));
String url = requireNonNull(almSettingDto.getUrl(), "ALM url cannot be null");
RepositoryList gsonBBSRepoList = bitbucketServerRestClient.getRepos(url, pat, projectKey, repoName);
Map<String, String> sqProjectsKeyByBBSKey = getSqProjectsKeyByBBSKey(dbSession, almSettingDto, gsonBBSRepoList);
List<BBSRepo> bbsRepos = gsonBBSRepoList.getValues().stream().map(gsonBBSRepo -> toBBSRepo(gsonBBSRepo, sqProjectsKeyByBBSKey)).collect(toList());
SearchBitbucketserverReposWsResponse.Builder builder = SearchBitbucketserverReposWsResponse.newBuilder().setIsLastPage(gsonBBSRepoList.isLastPage()).addAllRepositories(bbsRepos);
return builder.build();
}
}
use of org.sonar.alm.client.bitbucketserver.RepositoryList in project sonarqube by SonarSource.
the class SearchBitbucketServerReposActionTest method return_empty_list_when_no_bbs_repo.
@Test
public void return_empty_list_when_no_bbs_repo() {
RepositoryList gsonBBSRepoList = new RepositoryList();
gsonBBSRepoList.setLastPage(true);
gsonBBSRepoList.setValues(new ArrayList<>());
when(bitbucketServerRestClient.getRepos(any(), any(), any(), any())).thenReturn(gsonBBSRepoList);
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
});
ProjectDto projectDto = db.components().insertPrivateProjectDto();
db.almSettings().insertBitbucketProjectAlmSetting(almSetting, projectDto, s -> s.setAlmRepo("projectKey2"), s -> s.setAlmSlug("repo-slug-2"));
AlmIntegrations.SearchBitbucketserverReposWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(SearchBitbucketserverReposWsResponse.class);
assertThat(response.getIsLastPage()).isTrue();
assertThat(response.getRepositoriesList()).isEmpty();
}
Aggregations