use of org.sonar.db.alm.setting.ProjectAlmSettingDto in project sonarqube by SonarSource.
the class ListGithubRepositoriesAction method doHandle.
private AlmIntegrations.ListGithubRepositoriesWsResponse doHandle(Request request) {
try (DbSession dbSession = dbClient.openSession(false)) {
userSession.checkLoggedIn().checkPermission(PROVISION_PROJECTS);
String almSettingKey = request.mandatoryParam(PARAM_ALM_SETTING);
AlmSettingDto almSettingDto = dbClient.almSettingDao().selectByKey(dbSession, almSettingKey).orElseThrow(() -> new NotFoundException(String.format("GitHub ALM Setting '%s' not found", almSettingKey)));
String userUuid = requireNonNull(userSession.getUuid(), "User UUID is not null");
String url = requireNonNull(almSettingDto.getUrl(), String.format("No URL set for GitHub ALM '%s'", almSettingKey));
AccessToken accessToken = dbClient.almPatDao().selectByUserAndAlmSetting(dbSession, userUuid, almSettingDto).map(AlmPatDto::getPersonalAccessToken).map(UserAccessToken::new).orElseThrow(() -> new IllegalArgumentException("No personal access token found"));
int pageIndex = request.hasParam(PAGE) ? request.mandatoryParamAsInt(PAGE) : 1;
int pageSize = request.hasParam(PAGE_SIZE) ? request.mandatoryParamAsInt(PAGE_SIZE) : 100;
GithubApplicationClient.Repositories repositories = githubApplicationClient.listRepositories(url, accessToken, request.mandatoryParam(PARAM_ORGANIZATION), request.param(TEXT_QUERY), pageIndex, pageSize);
AlmIntegrations.ListGithubRepositoriesWsResponse.Builder response = AlmIntegrations.ListGithubRepositoriesWsResponse.newBuilder().setPaging(Common.Paging.newBuilder().setPageIndex(pageIndex).setPageSize(pageSize).setTotal(repositories.getTotal()).build());
List<Repository> repositoryList = repositories.getRepositories();
if (repositoryList != null) {
Set<String> repo = repositoryList.stream().map(Repository::getFullName).collect(Collectors.toSet());
List<ProjectAlmSettingDto> projectAlmSettingDtos = projectAlmSettingDao.selectByAlmSettingAndRepos(dbSession, almSettingDto, repo);
Map<String, ProjectDto> projectsDtoByAlmRepo = getProjectDtoByAlmRepo(dbSession, projectAlmSettingDtos);
for (Repository repository : repositoryList) {
AlmIntegrations.GithubRepository.Builder builder = AlmIntegrations.GithubRepository.newBuilder().setId(repository.getId()).setKey(repository.getFullName()).setName(repository.getName()).setUrl(repository.getUrl());
if (projectsDtoByAlmRepo.containsKey(repository.getFullName())) {
Optional.ofNullable(projectsDtoByAlmRepo.get(repository.getFullName())).ifPresent(p -> builder.setSqProjectKey(p.getKey()));
}
response.addRepositories(builder.build());
}
}
return response.build();
}
}
use of org.sonar.db.alm.setting.ProjectAlmSettingDto in project sonarqube by SonarSource.
the class ImportAzureProjectAction method populatePRSetting.
private void populatePRSetting(DbSession dbSession, GsonAzureRepo repo, ComponentDto componentDto, AlmSettingDto almSettingDto) {
ProjectAlmSettingDto projectAlmSettingDto = new ProjectAlmSettingDto().setAlmSettingUuid(almSettingDto.getUuid()).setAlmRepo(repo.getName()).setAlmSlug(repo.getProject().getName()).setProjectUuid(componentDto.uuid()).setMonorepo(false);
dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name(), componentDto.getKey());
}
use of org.sonar.db.alm.setting.ProjectAlmSettingDto 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.sonar.db.alm.setting.ProjectAlmSettingDto 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.sonar.db.alm.setting.ProjectAlmSettingDto 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