use of org.sonar.alm.client.bitbucketserver.Repository in project sonarqube by SonarSource.
the class SearchBitbucketServerReposActionTest method getGsonBBSRepo2.
private Repository getGsonBBSRepo2() {
Repository gsonBBSRepo = new Repository();
gsonBBSRepo.setId(3L);
gsonBBSRepo.setName("repoName2");
Project project = new Project();
project.setName("projectName2");
project.setKey("projectKey2");
project.setId(4L);
gsonBBSRepo.setProject(project);
gsonBBSRepo.setSlug("repo-slug-2");
return gsonBBSRepo;
}
use of org.sonar.alm.client.bitbucketserver.Repository in project sonarqube by SonarSource.
the class SearchBitbucketServerReposActionTest method before.
@Before
public void before() {
RepositoryList gsonBBSRepoList = new RepositoryList();
gsonBBSRepoList.setLastPage(true);
List<Repository> values = new ArrayList<>();
values.add(getGsonBBSRepo1());
values.add(getGsonBBSRepo2());
gsonBBSRepoList.setValues(values);
when(bitbucketServerRestClient.getRepos(any(), any(), any(), any())).thenReturn(gsonBBSRepoList);
}
use of org.sonar.alm.client.bitbucketserver.Repository in project sonarqube by SonarSource.
the class ImportBitbucketServerProjectAction method doHandle.
private Projects.CreateWsResponse doHandle(Request request) {
importHelper.checkProvisionProjectPermission();
AlmSettingDto almSettingDto = importHelper.getAlmSetting(request);
String userUuid = importHelper.getUserUuid();
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<AlmPatDto> almPatDto = dbClient.almPatDao().selectByUserAndAlmSetting(dbSession, userUuid, almSettingDto);
String pat = almPatDto.map(AlmPatDto::getPersonalAccessToken).orElseThrow(() -> new IllegalArgumentException(String.format("personal access token for '%s' is missing", almSettingDto.getKey())));
String projectKey = request.mandatoryParam(PARAM_PROJECT_KEY);
String repoSlug = request.mandatoryParam(PARAM_REPO_SLUG);
String url = requireNonNull(almSettingDto.getUrl(), "ALM url cannot be null");
Repository repo = bitbucketServerRestClient.getRepo(url, pat, projectKey, repoSlug);
String defaultBranchName = getDefaultBranchName(pat, projectKey, repoSlug, url);
ComponentDto componentDto = createProject(dbSession, repo, defaultBranchName);
populatePRSetting(dbSession, repo, componentDto, almSettingDto);
componentUpdater.commitAndIndex(dbSession, componentDto);
return toCreateResponse(componentDto);
}
}
use of org.sonar.alm.client.bitbucketserver.Repository 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");
}
use of org.sonar.alm.client.bitbucketserver.Repository in project sonarqube by SonarSource.
the class ImportBitbucketServerProjectActionTest method import_project.
@Test
public void import_project() {
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(defaultBranchesList);
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();
assertThat(result.getKey()).isEqualTo(project.getKey() + "_" + repo.getSlug());
assertThat(result.getName()).isEqualTo(repo.getName());
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
assertThat(projectDto).isPresent();
assertThat(db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), projectDto.get())).isPresent();
}
Aggregations