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");
}
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);
}
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));
}
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");
}
Aggregations