From 0cd8882fb7d443c91af1848b0a214ddd118b0c6a Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Fri, 4 Jun 2021 17:44:23 +0200 Subject: [PATCH] SONAR-14916 Add URL to BitbucketCloud instances --- .../org/sonar/server/almsettings/ws/ListAction.java | 10 +++++++++- .../sonar/server/almsettings/ws/ListActionTest.java | 5 +++-- .../org/sonar/server/almsettings/ws/list-example.json | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/ListAction.java index 13789c93943..2b3faff5e6c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/ListAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/ws/ListAction.java @@ -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()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/ListActionTest.java index 5cbd4aa900f..4532cf60019 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/ListActionTest.java @@ -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") diff --git a/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/almsettings/ws/list-example.json b/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/almsettings/ws/list-example.json index ff49519340c..366bada3a2c 100644 --- a/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/almsettings/ws/list-example.json +++ b/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/almsettings/ws/list-example.json @@ -17,7 +17,7 @@ { "key": "Bitbucket Cloud - Dev Team", "alm": "bitbucketcloud", - "url": "https://bitbucket.org" + "url": "https://bitbucket.org/workspace/" }, { "key": "GitLab - Dev Team", -- 2.39.5