use of org.sonarqube.ws.AlmIntegrations.AzureRepo in project sonarqube by SonarSource.
the class SearchAzureReposAction method toAzureRepo.
private static AzureRepo toAzureRepo(GsonAzureRepo azureRepo, Map<ProjectKeyName, ProjectDto> sqProjectsKeyByAzureKey) {
AzureRepo.Builder builder = AzureRepo.newBuilder().setName(azureRepo.getName()).setProjectName(azureRepo.getProject().getName());
ProjectDto projectDto = sqProjectsKeyByAzureKey.get(ProjectKeyName.from(azureRepo));
if (projectDto != null) {
builder.setSqProjectName(projectDto.getName());
builder.setSqProjectKey(projectDto.getKey());
}
return builder.build();
}
use of org.sonarqube.ws.AlmIntegrations.AzureRepo in project sonarqube by SonarSource.
the class SearchAzureReposAction method doHandle.
private SearchAzureReposWsResponse 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 searchQuery = request.param(PARAM_SEARCH_QUERY);
String pat = almPatDto.map(AlmPatDto::getPersonalAccessToken).orElseThrow(() -> new IllegalArgumentException("No personal access token found"));
String url = requireNonNull(almSettingDto.getUrl(), "ALM url cannot be null");
GsonAzureRepoList gsonAzureRepoList = azureDevOpsHttpClient.getRepos(url, pat, projectKey);
Map<ProjectKeyName, ProjectDto> sqProjectsKeyByAzureKey = getSqProjectsKeyByCustomKey(dbSession, almSettingDto, gsonAzureRepoList);
List<AzureRepo> repositories = gsonAzureRepoList.getValues().stream().filter(r -> isSearchOnlyByProjectName(searchQuery) || doesSearchCriteriaMatchProjectOrRepo(r, searchQuery)).map(repo -> toAzureRepo(repo, sqProjectsKeyByAzureKey)).sorted(comparing(AzureRepo::getName, String::compareToIgnoreCase)).collect(toList());
LOG.debug(repositories.toString());
return SearchAzureReposWsResponse.newBuilder().addAllRepositories(repositories).build();
}
}
Aggregations