Search in sources :

Example 1 with ProjectAlmSettingDto

use of org.sonar.db.alm.setting.ProjectAlmSettingDto in project sonarqube by SonarSource.

the class ImportBitbucketCloudRepoAction method populatePRSetting.

private void populatePRSetting(DbSession dbSession, Repository repo, ComponentDto componentDto, AlmSettingDto almSettingDto) {
    ProjectAlmSettingDto projectAlmSettingDto = new ProjectAlmSettingDto().setAlmSettingUuid(almSettingDto.getUuid()).setAlmRepo(repo.getSlug()).setProjectUuid(componentDto.uuid()).setMonorepo(false);
    dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name(), componentDto.getKey());
}
Also used : ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto)

Example 2 with ProjectAlmSettingDto

use of org.sonar.db.alm.setting.ProjectAlmSettingDto in project sonarqube by SonarSource.

the class ImportBitbucketServerProjectAction method populatePRSetting.

private void populatePRSetting(DbSession dbSession, Repository repo, ComponentDto componentDto, AlmSettingDto almSettingDto) {
    ProjectAlmSettingDto projectAlmSettingDto = new ProjectAlmSettingDto().setAlmSettingUuid(almSettingDto.getUuid()).setAlmRepo(repo.getProject().getKey()).setAlmSlug(repo.getSlug()).setProjectUuid(componentDto.uuid()).setMonorepo(false);
    dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name(), componentDto.getKey());
}
Also used : ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto)

Example 3 with ProjectAlmSettingDto

use of org.sonar.db.alm.setting.ProjectAlmSettingDto in project sonarqube by SonarSource.

the class ImportGithubProjectAction method populatePRSetting.

private void populatePRSetting(DbSession dbSession, Repository repo, ComponentDto componentDto, AlmSettingDto almSettingDto) {
    ProjectAlmSettingDto projectAlmSettingDto = new ProjectAlmSettingDto().setAlmSettingUuid(almSettingDto.getUuid()).setAlmRepo(repo.getFullName()).setAlmSlug(null).setProjectUuid(componentDto.uuid()).setSummaryCommentEnabled(true).setMonorepo(false);
    dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name(), componentDto.getKey());
}
Also used : ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto)

Example 4 with ProjectAlmSettingDto

use of org.sonar.db.alm.setting.ProjectAlmSettingDto in project sonarqube by SonarSource.

the class ImportBitbucketCloudRepoActionTest method import_project.

@Test
public void import_project() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).addPermission(PROVISION_PROJECTS);
    AlmSettingDto almSetting = db.almSettings().insertBitbucketCloudAlmSetting();
    db.almPats().insert(dto -> {
        dto.setAlmSettingUuid(almSetting.getUuid());
        dto.setUserUuid(user.getUuid());
    });
    Repository repo = getGsonBBCRepo();
    when(bitbucketCloudRestClient.getRepo(any(), any(), any())).thenReturn(repo);
    Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("repositorySlug", "repo-slug-1").executeProtobuf(Projects.CreateWsResponse.class);
    Projects.CreateWsResponse.Project result = response.getProject();
    assertThat(result.getKey()).isEqualTo(almSetting.getAppId() + "_" + repo.getSlug());
    assertThat(result.getName()).isEqualTo(repo.getName());
    Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
    assertThat(projectDto).isPresent();
    Optional<ProjectAlmSettingDto> projectAlmSettingDto = db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), projectDto.get());
    assertThat(projectAlmSettingDto).isPresent();
    assertThat(projectAlmSettingDto.get().getAlmRepo()).isEqualTo("repo-slug-1");
    Optional<BranchDto> branchDto = db.getDbClient().branchDao().selectByBranchKey(db.getSession(), projectDto.get().getUuid(), "develop");
    assertThat(branchDto).isPresent();
    assertThat(branchDto.get().isMain()).isTrue();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) UserDto(org.sonar.db.user.UserDto) Projects(org.sonarqube.ws.Projects) Repository(org.sonar.alm.client.bitbucket.bitbucketcloud.Repository) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) Test(org.junit.Test)

Example 5 with ProjectAlmSettingDto

use of org.sonar.db.alm.setting.ProjectAlmSettingDto in project sonarqube by SonarSource.

the class ImportAzureProjectActionTest method import_project.

@Test
public void import_project() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).addPermission(PROVISION_PROJECTS);
    AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting();
    db.almPats().insert(dto -> {
        dto.setAlmSettingUuid(almSetting.getUuid());
        dto.setPersonalAccessToken(almSetting.getDecryptedPersonalAccessToken(encryption));
        dto.setUserUuid(user.getUuid());
    });
    GsonAzureRepo repo = getGsonAzureRepo();
    when(azureDevOpsHttpClient.getRepo(almSetting.getUrl(), almSetting.getDecryptedPersonalAccessToken(encryption), "project-name", "repo-name")).thenReturn(repo);
    Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectName", "project-name").setParam("repositoryName", "repo-name").executeProtobuf(Projects.CreateWsResponse.class);
    Projects.CreateWsResponse.Project result = response.getProject();
    assertThat(result.getKey()).isEqualTo(repo.getProject().getName() + "_" + repo.getName());
    assertThat(result.getName()).isEqualTo(repo.getName());
    Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
    assertThat(projectDto).isPresent();
    Optional<ProjectAlmSettingDto> projectAlmSettingDto = db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), projectDto.get());
    assertThat(projectAlmSettingDto.get().getAlmRepo()).isEqualTo("repo-name");
    assertThat(projectAlmSettingDto.get().getAlmSettingUuid()).isEqualTo(almSetting.getUuid());
    assertThat(projectAlmSettingDto.get().getAlmSlug()).isEqualTo("project-name");
    Optional<BranchDto> mainBranch = db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get()).stream().filter(BranchDto::isMain).findFirst();
    assertThat(mainBranch).isPresent();
    assertThat(mainBranch.get().getKey()).hasToString("repo-default-branch");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) UserDto(org.sonar.db.user.UserDto) Projects(org.sonarqube.ws.Projects) GsonAzureRepo(org.sonar.alm.client.azure.GsonAzureRepo) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) Test(org.junit.Test)

Aggregations

ProjectAlmSettingDto (org.sonar.db.alm.setting.ProjectAlmSettingDto)11 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)7 Test (org.junit.Test)5 ProjectDto (org.sonar.db.project.ProjectDto)4 GetBindingWsResponse (org.sonarqube.ws.AlmSettings.GetBindingWsResponse)4 DbSession (org.sonar.db.DbSession)2 BranchDto (org.sonar.db.component.BranchDto)2 UserDto (org.sonar.db.user.UserDto)2 NotFoundException (org.sonar.server.exceptions.NotFoundException)2 Projects (org.sonarqube.ws.Projects)2 GsonAzureRepo (org.sonar.alm.client.azure.GsonAzureRepo)1 Repository (org.sonar.alm.client.bitbucket.bitbucketcloud.Repository)1 GithubApplicationClient (org.sonar.alm.client.github.GithubApplicationClient)1 Repository (org.sonar.alm.client.github.GithubApplicationClient.Repository)1 AccessToken (org.sonar.alm.client.github.security.AccessToken)1 UserAccessToken (org.sonar.alm.client.github.security.UserAccessToken)1 AlmPatDto (org.sonar.db.alm.pat.AlmPatDto)1