From 99c4855929e0f2296171c3fc1d1db937d25b8967 Mon Sep 17 00:00:00 2001 From: Zipeng WU Date: Thu, 20 May 2021 16:02:23 +0200 Subject: [PATCH] SONAR-14805 use almRepo to store BBC repository slug --- .../ws/bitbucketcloud/ImportBitbucketCloudRepoAction.java | 3 +-- .../bitbucketcloud/SearchBitbucketCloudReposAction.java | 6 +++--- .../ImportBitbucketCloudRepoActionTest.java | 5 ++++- .../SearchBitbucketCloudReposActionTest.java | 8 ++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoAction.java index 063d53fd2fa..6c69b4410c2 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoAction.java @@ -139,9 +139,8 @@ public class ImportBitbucketCloudRepoAction implements AlmIntegrationsWsAction { private void populatePRSetting(DbSession dbSession, Repository repo, ComponentDto componentDto, AlmSettingDto almSettingDto) { ProjectAlmSettingDto projectAlmSettingDto = new ProjectAlmSettingDto() .setAlmSettingUuid(almSettingDto.getUuid()) - // PR decoration reads almRepo + // Bitbucket Cloud PR decoration reads almRepo .setAlmRepo(repo.getSlug()) - .setAlmSlug(repo.getSlug()) .setProjectUuid(componentDto.uuid()) .setMonorepo(false); dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposAction.java index 5675392144e..191d0b440b7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposAction.java @@ -135,12 +135,12 @@ public class SearchBitbucketCloudReposAction implements AlmIntegrationsWsAction } private Map getSqProjectKeyByRepoSlug(DbSession dbSession, AlmSettingDto almSettingDto, List repositories) { - Set slugs = repositories.stream().map(Repository::getSlug).collect(toSet()); + Set repoSlugs = repositories.stream().map(Repository::getSlug).collect(toSet()); - List projectAlmSettingDtos = dbClient.projectAlmSettingDao().selectByAlmSettingAndSlugs(dbSession, almSettingDto, slugs); + List projectAlmSettingDtos = dbClient.projectAlmSettingDao().selectByAlmSettingAndRepos(dbSession, almSettingDto, repoSlugs); Map repoSlugByProjectUuid = projectAlmSettingDtos.stream() - .collect(toMap(ProjectAlmSettingDto::getProjectUuid, ProjectAlmSettingDto::getAlmSlug)); + .collect(toMap(ProjectAlmSettingDto::getProjectUuid, ProjectAlmSettingDto::getAlmRepo)); return dbClient.projectDao().selectByUuids(dbSession, repoSlugByProjectUuid.keySet()) .stream() diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionTest.java index b13cdfed22f..78af3c2c9a1 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoActionTest.java @@ -34,6 +34,7 @@ import org.sonar.core.util.SequenceUuidFactory; import org.sonar.db.DbTester; import org.sonar.db.alm.pat.AlmPatDto; import org.sonar.db.alm.setting.AlmSettingDto; +import org.sonar.db.alm.setting.ProjectAlmSettingDto; import org.sonar.db.component.BranchDto; import org.sonar.db.project.ProjectDto; import org.sonar.db.user.UserDto; @@ -107,7 +108,9 @@ public class ImportBitbucketCloudRepoActionTest { Optional projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey()); assertThat(projectDto).isPresent(); - assertThat(db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), projectDto.get())).isPresent(); + Optional projectAlmSettingDto = db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), projectDto.get()); + assertThat(projectAlmSettingDto).isPresent(); + assertThat(projectAlmSettingDto.get().getAlmRepo()).isEqualTo("repo-slug-1"); Optional branchDto = db.getDbClient().branchDao().selectByBranchKey(db.getSession(), projectDto.get().getUuid(), "develop"); assertThat(branchDto).isPresent(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposActionTest.java index 4d4ded4f9a1..14175d4d25f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketcloud/SearchBitbucketCloudReposActionTest.java @@ -77,7 +77,7 @@ public class SearchBitbucketCloudReposActionTest { dto.setUserUuid(user.getUuid()); }); ProjectDto projectDto = db.components().insertPrivateProjectDto(); - db.almSettings().insertBitbucketCloudProjectAlmSetting(almSetting, projectDto, s -> s.setAlmSlug("repo-slug-2")); + db.almSettings().insertBitbucketCloudProjectAlmSetting(almSetting, projectDto, s -> s.setAlmRepo("repo-slug-2")); SearchBitbucketcloudReposWsResponse response = ws.newRequest() .setParam("almSetting", almSetting.getKey()) @@ -107,8 +107,8 @@ public class SearchBitbucketCloudReposActionTest { }); ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setDbKey("B")); ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setDbKey("A")); - db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project1, s -> s.setAlmSlug("repo-slug-2")); - db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project2, s -> s.setAlmSlug("repo-slug-2")); + db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project1, s -> s.setAlmRepo("repo-slug-2")); + db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project2, s -> s.setAlmRepo("repo-slug-2")); SearchBitbucketcloudReposWsResponse response = ws.newRequest() .setParam("almSetting", almSetting.getKey()) @@ -134,7 +134,7 @@ public class SearchBitbucketCloudReposActionTest { dto.setUserUuid(user.getUuid()); }); ProjectDto projectDto = db.components().insertPrivateProjectDto(); - db.almSettings().insertBitbucketCloudProjectAlmSetting(almSetting, projectDto, s -> s.setAlmRepo("projectKey2"), s -> s.setAlmSlug("repo-slug-2")); + db.almSettings().insertBitbucketCloudProjectAlmSetting(almSetting, projectDto, s -> s.setAlmRepo("repo-slug-2")); SearchBitbucketcloudReposWsResponse response = ws.newRequest() .setParam("almSetting", almSetting.getKey()) -- 2.39.5