Search in sources :

Example 1 with BranchesList

use of org.sonar.alm.client.bitbucketserver.BranchesList in project sonarqube by SonarSource.

the class ImportBitbucketServerProjectActionTest method handle_givenDefaultBranchNamedDefault_updateDefaultBranchNameToDefault.

@Test
public void handle_givenDefaultBranchNamedDefault_updateDefaultBranchNameToDefault() {
    BranchesList branchesList = new BranchesList();
    Branch branch = new Branch("default", true);
    branchesList.addBranch(branch);
    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());
    });
    Project project = getGsonBBSProject();
    Repository repo = getGsonBBSRepo(project);
    when(bitbucketServerRestClient.getRepo(any(), any(), any(), any())).thenReturn(repo);
    when(bitbucketServerRestClient.getBranches(any(), any(), any(), any())).thenReturn(branchesList);
    Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectKey", "projectKey").setParam("repositorySlug", "repo-slug").executeProtobuf(Projects.CreateWsResponse.class);
    Projects.CreateWsResponse.Project result = response.getProject();
    Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
    Collection<BranchDto> branchDtos = db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get());
    List<BranchDto> collect = branchDtos.stream().filter(BranchDto::isMain).collect(Collectors.toList());
    String mainBranchName = collect.iterator().next().getKey();
    assertThat(mainBranchName).isEqualTo("default");
}
Also used : BranchesList(org.sonar.alm.client.bitbucketserver.BranchesList) ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) UserDto(org.sonar.db.user.UserDto) Projects(org.sonarqube.ws.Projects) Project(org.sonar.alm.client.bitbucketserver.Project) Repository(org.sonar.alm.client.bitbucketserver.Repository) Branch(org.sonar.alm.client.bitbucketserver.Branch) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 2 with BranchesList

use of org.sonar.alm.client.bitbucketserver.BranchesList in project sonarqube by SonarSource.

the class ImportBitbucketServerProjectAction method getDefaultBranchName.

private String getDefaultBranchName(String pat, String projectKey, String repoSlug, String url) {
    BranchesList branches = bitbucketServerRestClient.getBranches(url, pat, projectKey, repoSlug);
    Optional<Branch> defaultBranch = branches.findDefaultBranch();
    return defaultBranch.map(Branch::getName).orElse(null);
}
Also used : BranchesList(org.sonar.alm.client.bitbucketserver.BranchesList) Branch(org.sonar.alm.client.bitbucketserver.Branch)

Example 3 with BranchesList

use of org.sonar.alm.client.bitbucketserver.BranchesList in project sonarqube by SonarSource.

the class ImportBitbucketServerProjectActionTest method beforeAll.

@BeforeClass
public static void beforeAll() {
    Branch defaultBranch = new Branch("default", true);
    defaultBranchesList = new BranchesList(Collections.singletonList(defaultBranch));
}
Also used : BranchesList(org.sonar.alm.client.bitbucketserver.BranchesList) Branch(org.sonar.alm.client.bitbucketserver.Branch) BeforeClass(org.junit.BeforeClass)

Example 4 with BranchesList

use of org.sonar.alm.client.bitbucketserver.BranchesList in project sonarqube by SonarSource.

the class ImportBitbucketServerProjectActionTest method handle_givenNoDefaultBranchFound_doNotUpdateDefaultBranchName.

@Test
public void handle_givenNoDefaultBranchFound_doNotUpdateDefaultBranchName() {
    BranchesList branchesList = new BranchesList();
    Branch branch = new Branch("not_a_master", false);
    branchesList.addBranch(branch);
    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());
    });
    Project project = getGsonBBSProject();
    Repository repo = getGsonBBSRepo(project);
    when(bitbucketServerRestClient.getRepo(any(), any(), any(), any())).thenReturn(repo);
    when(bitbucketServerRestClient.getBranches(any(), any(), any(), any())).thenReturn(branchesList);
    Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectKey", "projectKey").setParam("repositorySlug", "repo-slug").executeProtobuf(Projects.CreateWsResponse.class);
    Projects.CreateWsResponse.Project result = response.getProject();
    Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
    Collection<BranchDto> branchDtos = db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get());
    List<BranchDto> collect = branchDtos.stream().filter(BranchDto::isMain).collect(Collectors.toList());
    String mainBranchName = collect.iterator().next().getKey();
    assertThat(mainBranchName).isEqualTo("master");
}
Also used : BranchesList(org.sonar.alm.client.bitbucketserver.BranchesList) ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) UserDto(org.sonar.db.user.UserDto) Projects(org.sonarqube.ws.Projects) Project(org.sonar.alm.client.bitbucketserver.Project) Repository(org.sonar.alm.client.bitbucketserver.Repository) Branch(org.sonar.alm.client.bitbucketserver.Branch) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Aggregations

Branch (org.sonar.alm.client.bitbucketserver.Branch)4 BranchesList (org.sonar.alm.client.bitbucketserver.BranchesList)4 Test (org.junit.Test)2 Project (org.sonar.alm.client.bitbucketserver.Project)2 Repository (org.sonar.alm.client.bitbucketserver.Repository)2 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)2 BranchDto (org.sonar.db.component.BranchDto)2 ProjectDto (org.sonar.db.project.ProjectDto)2 UserDto (org.sonar.db.user.UserDto)2 Projects (org.sonarqube.ws.Projects)2 BeforeClass (org.junit.BeforeClass)1