From 34b205a13ee7cfa351003bfd804e4a32a41e7390 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 24 Oct 2019 11:15:04 +0200 Subject: [PATCH] SONAR-12515 Allow binding of projects on Bitbucket ALM --- .../db/almsettings/AlmSettingsDbTester.java | 6 + .../db/almsettings/AlmSettingsTesting.java | 13 +- .../almsettings/AlmSettingsWsModule.java | 1 + .../server/almsettings/GetBindingAction.java | 1 + .../SetBitbucketBindingAction.java | 93 +++++++++++ .../server/almsettings/list-example.json | 5 + .../almsettings/GetBindingActionTest.java | 25 ++- .../server/almsettings/ListActionTest.java | 17 +- .../SetBitbucketBindingActionTest.java | 157 ++++++++++++++++++ .../almsettings/AlmSettingsService.java | 15 ++ .../SetBitbucketBindingRequest.java | 84 ++++++++++ .../src/main/protobuf/ws-alm_settings.proto | 1 + 12 files changed, 405 insertions(+), 13 deletions(-) create mode 100644 server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/SetBitbucketBindingAction.java create mode 100644 server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/SetBitbucketBindingActionTest.java create mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/SetBitbucketBindingRequest.java diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsDbTester.java index cd83d9d5f26..aedee5b7d89 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsDbTester.java @@ -29,6 +29,7 @@ import static java.util.Arrays.stream; import static org.sonar.db.almsettings.AlmSettingsTesting.newAzureAlmSettingDto; import static org.sonar.db.almsettings.AlmSettingsTesting.newAzureProjectAlmSettingDto; import static org.sonar.db.almsettings.AlmSettingsTesting.newBitbucketAlmSettingDto; +import static org.sonar.db.almsettings.AlmSettingsTesting.newBitbucketProjectAlmSettingDto; import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto; import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubProjectAlmSettingDto; @@ -64,6 +65,11 @@ public class AlmSettingsDbTester { return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project)); } + @SafeVarargs + public final ProjectAlmSettingDto insertBitbucketProjectAlmSetting(AlmSettingDto bitbucketAlmSetting, ComponentDto project, Consumer... populators) { + return insertProjectAlmSetting(newBitbucketProjectAlmSettingDto(bitbucketAlmSetting, project), populators); + } + @SafeVarargs private final ProjectAlmSettingDto insertProjectAlmSetting(ProjectAlmSettingDto dto, Consumer... populators) { stream(populators).forEach(p -> p.accept(dto)); diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsTesting.java index 74d32a7c422..dc5e8f8176f 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsTesting.java @@ -56,13 +56,20 @@ public class AlmSettingsTesting { return new ProjectAlmSettingDto() .setAlmSettingUuid(githubAlmSetting.getUuid()) .setProjectUuid(project.uuid()) - .setAlmRepo(randomAlphanumeric(256)) - .setAlmSlug(randomAlphanumeric(256)); + .setAlmRepo(randomAlphanumeric(256)); } - public static ProjectAlmSettingDto newAzureProjectAlmSettingDto(AlmSettingDto githubAlmSetting, ComponentDto project) { + static ProjectAlmSettingDto newAzureProjectAlmSettingDto(AlmSettingDto githubAlmSetting, ComponentDto project) { return new ProjectAlmSettingDto() .setAlmSettingUuid(githubAlmSetting.getUuid()) .setProjectUuid(project.uuid()); } + + public static ProjectAlmSettingDto newBitbucketProjectAlmSettingDto(AlmSettingDto githubAlmSetting, ComponentDto project) { + return new ProjectAlmSettingDto() + .setAlmSettingUuid(githubAlmSetting.getUuid()) + .setProjectUuid(project.uuid()) + .setAlmRepo(randomAlphanumeric(256)) + .setAlmSlug(randomAlphanumeric(256)); + } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/AlmSettingsWsModule.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/AlmSettingsWsModule.java index d3eeffcb354..eabbb626129 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/AlmSettingsWsModule.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/AlmSettingsWsModule.java @@ -44,6 +44,7 @@ public class AlmSettingsWsModule extends Module { UpdateAzureAction.class, // Bitbucket DevOps specific actions CreateBitBucketAction.class, + SetBitbucketBindingAction.class, UpdateBitbucketAction.class ); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/GetBindingAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/GetBindingAction.java index e210967e937..62a9af8d9e8 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/GetBindingAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/GetBindingAction.java @@ -88,6 +88,7 @@ public class GetBindingAction implements AlmSettingsWsAction { .setKey(almSetting.getKey()); ofNullable(projectAlmSetting.getAlmRepo()).ifPresent(builder::setRepository); ofNullable(almSetting.getUrl()).ifPresent(builder::setUrl); + ofNullable(projectAlmSetting.getAlmSlug()).ifPresent(builder::setSlug); return builder.build(); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/SetBitbucketBindingAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/SetBitbucketBindingAction.java new file mode 100644 index 00000000000..089251bd48e --- /dev/null +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/SetBitbucketBindingAction.java @@ -0,0 +1,93 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.almsettings; + +import org.sonar.api.server.ws.Request; +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.AlmSettingDto; +import org.sonar.db.alm.setting.ProjectAlmSettingDto; +import org.sonar.db.component.ComponentDto; + +public class SetBitbucketBindingAction implements AlmSettingsWsAction { + + private static final String PARAM_ALM_SETTING = "almSetting"; + private static final String PARAM_PROJECT = "project"; + private static final String PARAM_REPOSITORY = "repository"; + private static final String PARAM_SLUG = "slug"; + + private final DbClient dbClient; + private final AlmSettingsSupport almSettingsSupport; + + public SetBitbucketBindingAction(DbClient dbClient, AlmSettingsSupport almSettingsSupport) { + this.dbClient = dbClient; + this.almSettingsSupport = almSettingsSupport; + } + + @Override + public void define(WebService.NewController context) { + WebService.NewAction action = context.createAction("set_bitbucket_binding") + .setDescription("Bind a Bitbucket ALM instance to a project.
" + + "If the project was already bound to a previous Bitbucket ALM instance, the binding will be updated to the new one." + + "Requires the 'Administer' permission on the project") + .setPost(true) + .setSince("8.1") + .setHandler(this); + + action.createParam(PARAM_ALM_SETTING) + .setRequired(true) + .setDescription("GitHub ALM setting key"); + action.createParam(PARAM_PROJECT) + .setRequired(true) + .setDescription("Project key"); + action.createParam(PARAM_REPOSITORY) + .setRequired(true) + .setDescription("Bitbucket repository key"); + action.createParam(PARAM_SLUG) + .setRequired(true) + .setDescription("Bitbucket repository slug"); + } + + @Override + public void handle(Request request, Response response) throws Exception { + doHandle(request); + response.noContent(); + } + + private void doHandle(Request request) { + String almSetting = request.mandatoryParam(PARAM_ALM_SETTING); + String projectKey = request.mandatoryParam(PARAM_PROJECT); + String repository = request.mandatoryParam(PARAM_REPOSITORY); + String slug = request.mandatoryParam(PARAM_SLUG); + try (DbSession dbSession = dbClient.openSession(false)) { + ComponentDto project = almSettingsSupport.getProject(dbSession, projectKey); + AlmSettingDto almSettingDto = almSettingsSupport.getAlmSetting(dbSession, almSetting); + dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, new ProjectAlmSettingDto() + .setProjectUuid(project.uuid()) + .setAlmSettingUuid(almSettingDto.getUuid()) + .setAlmRepo(repository) + .setAlmSlug(slug)); + dbSession.commit(); + } + } + +} diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almsettings/list-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almsettings/list-example.json index 444283d3960..ddd8ee48821 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almsettings/list-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almsettings/list-example.json @@ -9,6 +9,11 @@ "key": "Azure Server - Dev Team", "alm": "azure", "url": "https://azure.com" + }, + { + "key": "Bitbucket Server - Dev Team", + "alm": "bitbucket", + "url": "https://bitbucket.enterprise.com" } ] } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/GetBindingActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/GetBindingActionTest.java index 54fe6fc39e7..af3b09f08f6 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/GetBindingActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/GetBindingActionTest.java @@ -77,19 +77,38 @@ public class GetBindingActionTest { UserDto user = db.users().insertUser(); ComponentDto project = db.components().insertPrivateProject(); userSession.logIn(user).addProjectPermission(ADMIN, project); - AlmSettingDto githubAlmSetting = db.almSettings().insertAzureAlmSetting(); - db.almSettings().insertAzureProjectAlmSetting(githubAlmSetting, project); + AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting(); + db.almSettings().insertAzureProjectAlmSetting(almSetting, project); GetBindingWsResponse response = ws.newRequest() .setParam("project", project.getKey()) .executeProtobuf(GetBindingWsResponse.class); assertThat(response.getAlm()).isEqualTo(AlmSettings.Alm.azure); - assertThat(response.getKey()).isEqualTo(githubAlmSetting.getKey()); + assertThat(response.getKey()).isEqualTo(almSetting.getKey()); assertThat(response.hasRepository()).isFalse(); assertThat(response.hasUrl()).isFalse(); } + @Test + public void get_bitbucket_project_binding() { + UserDto user = db.users().insertUser(); + ComponentDto project = db.components().insertPrivateProject(); + userSession.logIn(user).addProjectPermission(ADMIN, project); + AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting(); + ProjectAlmSettingDto projectAlmSettingDto = db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project); + + GetBindingWsResponse response = ws.newRequest() + .setParam("project", project.getKey()) + .executeProtobuf(GetBindingWsResponse.class); + + assertThat(response.getAlm()).isEqualTo(AlmSettings.Alm.bitbucket); + assertThat(response.getKey()).isEqualTo(almSetting.getKey()); + assertThat(response.getRepository()).isEqualTo(projectAlmSettingDto.getAlmRepo()); + assertThat(response.getUrl()).isEqualTo(almSetting.getUrl()); + assertThat(response.getSlug()).isEqualTo(projectAlmSettingDto.getAlmSlug()); + } + @Test public void fail_when_project_does_not_exist() { UserDto user = db.users().insertUser(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ListActionTest.java index ca54685f6dc..2b32f27aa07 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ListActionTest.java @@ -62,6 +62,7 @@ public class ListActionTest { AlmSettingDto githubAlmSetting1 = db.almSettings().insertGitHubAlmSetting(); AlmSettingDto githubAlmSetting2 = db.almSettings().insertGitHubAlmSetting(); AlmSettingDto azureAlmSetting = db.almSettings().insertAzureAlmSetting(); + AlmSettingDto bitbucketAlmSetting = db.almSettings().insertBitbucketAlmSetting(); ListWsResponse response = ws.newRequest() .setParam("project", project.getKey()) @@ -72,8 +73,8 @@ public class ListActionTest { .containsExactlyInAnyOrder( tuple(AlmSettings.Alm.github, githubAlmSetting1.getKey(), true, githubAlmSetting1.getUrl()), tuple(AlmSettings.Alm.github, githubAlmSetting2.getKey(), true, githubAlmSetting2.getUrl()), - tuple(AlmSettings.Alm.azure, azureAlmSetting.getKey(), false, "") - ); + tuple(AlmSettings.Alm.azure, azureAlmSetting.getKey(), false, ""), + tuple(AlmSettings.Alm.bitbucket, bitbucketAlmSetting.getKey(), true, bitbucketAlmSetting.getUrl())); } @Test @@ -114,16 +115,18 @@ public class ListActionTest { AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting( almSettingDto -> almSettingDto .setKey("GitHub Server - Dev Team") - .setUrl("https://github.enterprise.com") - .setAppId("12345") - .setPrivateKey("54684654")); + .setUrl("https://github.enterprise.com")); db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project, projectAlmSetting -> projectAlmSetting.setAlmRepo("team/project")); AlmSettingDto azureAlmSetting = db.almSettings().insertAzureAlmSetting( almSettingDto -> almSettingDto .setKey("Azure Server - Dev Team") - .setUrl("https://azure.com") - .setPersonalAccessToken("abcdefg")); + .setUrl("https://azure.com")); db.almSettings().insertAzureProjectAlmSetting(azureAlmSetting, project); + AlmSettingDto bitbucketAlmSetting = db.almSettings().insertBitbucketAlmSetting( + almSettingDto -> almSettingDto + .setKey("Bitbucket Server - Dev Team") + .setUrl("https://bitbucket.enterprise.com")); + db.almSettings().insertBitbucketProjectAlmSetting(bitbucketAlmSetting, project); String response = ws.newRequest() .setParam("project", project.getKey()) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/SetBitbucketBindingActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/SetBitbucketBindingActionTest.java new file mode 100644 index 00000000000..0bda8a7bdf8 --- /dev/null +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/SetBitbucketBindingActionTest.java @@ -0,0 +1,157 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.server.almsettings; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.server.ws.WebService; +import org.sonar.db.DbTester; +import org.sonar.db.alm.setting.AlmSettingDto; +import org.sonar.db.alm.setting.ProjectAlmSettingDto; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.user.UserDto; +import org.sonar.server.component.ComponentFinder; +import org.sonar.server.exceptions.ForbiddenException; +import org.sonar.server.exceptions.NotFoundException; +import org.sonar.server.tester.UserSessionRule; +import org.sonar.server.ws.WsActionTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.groups.Tuple.tuple; +import static org.sonar.api.web.UserRole.ADMIN; +import static org.sonar.api.web.UserRole.USER; + +public class SetBitbucketBindingActionTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + @Rule + public UserSessionRule userSession = UserSessionRule.standalone(); + @Rule + public DbTester db = DbTester.create(); + + private WsActionTester ws = new WsActionTester(new SetBitbucketBindingAction(db.getDbClient(), + new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null)))); + + @Test + public void set_bitbucket_project_binding() { + UserDto user = db.users().insertUser(); + AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting(); + ComponentDto project = db.components().insertPrivateProject(); + userSession.logIn(user).addProjectPermission(ADMIN, project); + + ws.newRequest() + .setParam("almSetting", almSetting.getKey()) + .setParam("project", project.getKey()) + .setParam("repository", "myproject") + .setParam("slug", "123456") + .execute(); + + assertThat(db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), project).get()) + .extracting(ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid, ProjectAlmSettingDto::getAlmRepo, ProjectAlmSettingDto::getAlmSlug) + .containsOnly(almSetting.getUuid(), project.uuid(), "myproject", "123456"); + } + + @Test + public void override_existing_bitbucket_project_binding() { + UserDto user = db.users().insertUser(); + AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting(); + ComponentDto project = db.components().insertPrivateProject(); + db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project); + AlmSettingDto anotherAlmSetting = db.almSettings().insertBitbucketAlmSetting(); + userSession.logIn(user).addProjectPermission(ADMIN, project); + + ws.newRequest() + .setParam("almSetting", anotherAlmSetting.getKey()) + .setParam("project", project.getKey()) + .setParam("repository", "myproject") + .setParam("slug", "123456") + .execute(); + + assertThat(db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), project).get()) + .extracting(ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid, ProjectAlmSettingDto::getAlmRepo, ProjectAlmSettingDto::getAlmSlug) + .containsOnly(anotherAlmSetting.getUuid(), project.uuid(), "myproject", "123456"); + } + + @Test + public void fail_when_alm_setting_does_not_exist() { + UserDto user = db.users().insertUser(); + ComponentDto project = db.components().insertPrivateProject(); + userSession.logIn(user).addProjectPermission(ADMIN, project); + + expectedException.expect(NotFoundException.class); + expectedException.expectMessage("ALM setting with key 'unknown' cannot be found"); + + ws.newRequest() + .setParam("almSetting", "unknown") + .setParam("project", project.getKey()) + .setParam("repository", "myproject") + .setParam("slug", "123456") + .execute(); + } + + @Test + public void fail_when_project_does_not_exist() { + UserDto user = db.users().insertUser(); + AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting(); + ComponentDto project = db.components().insertPrivateProject(); + userSession.logIn(user).addProjectPermission(ADMIN, project); + + expectedException.expect(NotFoundException.class); + + ws.newRequest() + .setParam("almSetting", almSetting.getKey()) + .setParam("project", "unknown") + .setParam("repository", "myproject") + .setParam("slug", "123456") + .execute(); + } + + @Test + public void fail_when_missing_administer_permission_on_project() { + UserDto user = db.users().insertUser(); + AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting(); + ComponentDto project = db.components().insertPrivateProject(); + userSession.logIn(user).addProjectPermission(USER, project); + + expectedException.expect(ForbiddenException.class); + + ws.newRequest() + .setParam("almSetting", almSetting.getKey()) + .setParam("project", project.getKey()) + .setParam("repository", "myproject") + .setParam("slug", "123456") + .execute(); + } + + @Test + public void definition() { + WebService.Action def = ws.getDef(); + + assertThat(def.since()).isEqualTo("8.1"); + assertThat(def.isPost()).isTrue(); + assertThat(def.params()) + .extracting(WebService.Param::key, WebService.Param::isRequired) + .containsExactlyInAnyOrder(tuple("almSetting", true), tuple("project", true), tuple("repository", true), tuple("slug", true)); + } + +} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/AlmSettingsService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/AlmSettingsService.java index b99978ec45e..7cd7ca89474 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/AlmSettingsService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/AlmSettingsService.java @@ -170,6 +170,21 @@ public class AlmSettingsService extends BaseService { .setMediaType(MediaTypes.JSON)).content(); } + /** + * This is a POST request. + * @see Further information about this action online (including a response example) + * @since 8.1 + */ + public void setBitbucketBinding(SetBitbucketBindingRequest request) { + call( + new PostRequest(path("set_bitbucket_binding")) + .setParam("almSetting", request.getAlmSetting()) + .setParam("project", request.getProject()) + .setParam("repository", request.getRepositoryKey()) + .setParam("slug", request.getRepositorySlug()) + .setMediaType(MediaTypes.JSON)).content(); + } + /** * This is a POST request. * @see Further information about this action online (including a response example) diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/SetBitbucketBindingRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/SetBitbucketBindingRequest.java new file mode 100644 index 00000000000..ff916c1808c --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/SetBitbucketBindingRequest.java @@ -0,0 +1,84 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonarqube.ws.client.almsettings; + +import javax.annotation.Generated; + +/** + * This is a POST request. + * @see Further information about this action online (including a response example) + * @since 8.1 + */ +@Generated("sonar-ws-generator") +public class SetBitbucketBindingRequest { + + private String almSetting; + private String project; + private String repositoryKey; + private String repositorySlug; + + /** + * This is a mandatory parameter. + */ + public SetBitbucketBindingRequest setAlmSetting(String almSetting) { + this.almSetting = almSetting; + return this; + } + + public String getAlmSetting() { + return almSetting; + } + + /** + * This is a mandatory parameter. + */ + public SetBitbucketBindingRequest setProject(String project) { + this.project = project; + return this; + } + + public String getProject() { + return project; + } + + /** + * This is a mandatory parameter. + */ + public SetBitbucketBindingRequest setRepository(String repository) { + this.repositoryKey = repository; + return this; + } + + public String getRepositoryKey() { + return repositoryKey; + } + + /** + * This is a mandatory parameter. + */ + public SetBitbucketBindingRequest setSlug(String slug) { + this.repositorySlug = slug; + return this; + } + + public String getRepositorySlug() { + return repositorySlug; + } +} diff --git a/sonar-ws/src/main/protobuf/ws-alm_settings.proto b/sonar-ws/src/main/protobuf/ws-alm_settings.proto index ce1c9b825fb..abbae3a99b8 100644 --- a/sonar-ws/src/main/protobuf/ws-alm_settings.proto +++ b/sonar-ws/src/main/protobuf/ws-alm_settings.proto @@ -55,6 +55,7 @@ message GetBindingWsResponse { optional Alm alm = 2; optional string repository = 3; optional string url = 4; + optional string slug = 5; } enum Alm { -- 2.39.5