]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14916 Add URL to BitbucketCloud instances
authorJeremy Davis <jeremy.davis@sonarsource.com>
Fri, 4 Jun 2021 15:44:23 +0000 (17:44 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 9 Jun 2021 20:03:05 +0000 (20:03 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/ListAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/ListActionTest.java
server/sonar-webserver-webapi/src/test/resources/org/sonar/server/almsettings/ws/list-example.json

index 13789c939436770fa83538b3a0e0bb985feee60c..2b3faff5e6c29522650e94bfafe480bf1449371e 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.api.server.ws.Response;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
+import org.sonar.db.alm.setting.ALM;
 import org.sonar.db.alm.setting.AlmSettingDto;
 import org.sonar.db.project.ProjectDto;
 import org.sonar.server.component.ComponentFinder;
@@ -43,6 +44,7 @@ import static org.sonar.server.ws.WsUtils.writeProtobuf;
 public class ListAction implements AlmSettingsWsAction {
 
   private static final String PARAM_PROJECT = "project";
+  private static final String BITBUCKETCLOUD_ROOT_URL = "https://bitbucket.org/";
 
   private final DbClient dbClient;
   private final UserSession userSession;
@@ -98,7 +100,13 @@ public class ListAction implements AlmSettingsWsAction {
           AlmSetting.Builder almSettingBuilder = AlmSetting.newBuilder()
             .setKey(almSetting.getKey())
             .setAlm(AlmSettingsSupport.toAlmWs(almSetting.getAlm()));
-          ofNullable(almSetting.getUrl()).ifPresent(almSettingBuilder::setUrl);
+
+          if (almSetting.getAlm() == ALM.BITBUCKET_CLOUD) {
+            almSettingBuilder.setUrl(BITBUCKETCLOUD_ROOT_URL + almSetting.getAppId() + "/");
+          } else {
+            ofNullable(almSetting.getUrl()).ifPresent(almSettingBuilder::setUrl);
+          }
+
           return almSettingBuilder.build();
         })
         .collect(Collectors.toList());
index 5cbd4aa900f9aeb00f1bc139dd42b7944f342f4b..4532cf600195c600b283db37e51158d1bf131f96 100644 (file)
@@ -84,7 +84,8 @@ public class ListActionTest {
         tuple(AlmSettings.Alm.gitlab, gitlabAlmSetting.getKey(), true, gitlabAlmSetting.getUrl()),
         tuple(AlmSettings.Alm.gitlab, gitlabAlmSettingWithoutUrl.getKey(), false, ""),
         tuple(AlmSettings.Alm.bitbucket, bitbucketAlmSetting.getKey(), true, bitbucketAlmSetting.getUrl()),
-        tuple(AlmSettings.Alm.bitbucketcloud, bitbucketCloudAlmSetting.getKey(), false, ""));
+        tuple(AlmSettings.Alm.bitbucketcloud, bitbucketCloudAlmSetting.getKey(), true,
+          "https://bitbucket.org/" + bitbucketCloudAlmSetting.getAppId() + "/"));
   }
 
   @Test
@@ -194,7 +195,7 @@ public class ListActionTest {
     db.almSettings().insertBitbucketCloudAlmSetting(
       almSettingDto -> almSettingDto
         .setKey("Bitbucket Cloud - Dev Team")
-        .setUrl("https://bitbucket.org"));
+        .setAppId("workspace"));
     db.almSettings().insertGitlabAlmSetting(
       almSettingDto -> almSettingDto
         .setKey("GitLab - Dev Team")
index ff49519340c2d72f5ee514ca6f518d7f5bdd7008..366bada3a2c580692a4b75f3c288caba4c087578 100644 (file)
@@ -17,7 +17,7 @@
     {
       "key": "Bitbucket Cloud - Dev Team",
       "alm": "bitbucketcloud",
-      "url": "https://bitbucket.org"
+      "url": "https://bitbucket.org/workspace/"
     },
     {
       "key": "GitLab - Dev Team",