From b02a0a1458bca1771ac361c3acfd222e639f2f13 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 23 Oct 2019 11:30:18 +0200 Subject: [PATCH] SONAR-12515 Allow binding of projects on Azure ALM --- .../db/almsettings/AlmSettingsDbTester.java | 12 +- .../db/almsettings/AlmSettingsTesting.java | 6 + .../almsettings/AlmSettingsSupport.java | 2 +- .../almsettings/SetAzureBindingAction.java | 4 +- .../server/almsettings/list-example.json | 5 + .../almsettings/list_definitions-example.json | 7 + .../almsettings/CountBindingActionTest.java | 28 +++- .../almsettings/GetBindingActionTest.java | 20 ++- .../server/almsettings/ListActionTest.java | 16 +- .../ListDefinitionsActionTest.java | 8 +- .../SetAzureBindingActionTest.java | 147 ++++++++++++++++++ .../almsettings/AlmSettingsService.java | 16 +- ...ingRequest.java => GetBindingRequest.java} | 4 +- .../almsettings/SetAzureBindingRequest.java | 59 +++++++ 14 files changed, 314 insertions(+), 20 deletions(-) create mode 100644 server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/SetAzureBindingActionTest.java rename sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/{GetGithubBindingRequest.java => GetBindingRequest.java} (93%) create mode 100644 sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/SetAzureBindingRequest.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 f0cb2ee71fe..4a1c04ae067 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 @@ -27,6 +27,7 @@ import org.sonar.db.component.ComponentDto; 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.newGithubAlmSettingDto; import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubProjectAlmSettingDto; @@ -56,9 +57,15 @@ public class AlmSettingsDbTester { @SafeVarargs public final ProjectAlmSettingDto insertGitHubProjectAlmSetting(AlmSettingDto githubAlmSetting, ComponentDto project, Consumer... populators) { - ProjectAlmSettingDto dto = newGithubProjectAlmSettingDto(githubAlmSetting, project); - stream(populators).forEach(p -> p.accept(dto)); + return insertProjectAlmSetting(newGithubProjectAlmSettingDto(githubAlmSetting, project), populators); + } + + public ProjectAlmSettingDto insertAzureProjectAlmSetting(AlmSettingDto azureAlmSetting, ComponentDto project) { + return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project)); + } + private ProjectAlmSettingDto insertProjectAlmSetting(ProjectAlmSettingDto dto, Consumer... populators) { + stream(populators).forEach(p -> p.accept(dto)); db.getDbClient().projectAlmSettingDao().insertOrUpdate(db.getSession(), dto); db.commit(); return dto; @@ -66,7 +73,6 @@ public class AlmSettingsDbTester { private AlmSettingDto insert(AlmSettingDto dto, Consumer[] populators) { stream(populators).forEach(p -> p.accept(dto)); - db.getDbClient().almSettingDao().insert(db.getSession(), dto); db.commit(); return 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 99952b0aa96..74d32a7c422 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 @@ -59,4 +59,10 @@ public class AlmSettingsTesting { .setAlmRepo(randomAlphanumeric(256)) .setAlmSlug(randomAlphanumeric(256)); } + + public static ProjectAlmSettingDto newAzureProjectAlmSettingDto(AlmSettingDto githubAlmSetting, ComponentDto project) { + return new ProjectAlmSettingDto() + .setAlmSettingUuid(githubAlmSetting.getUuid()) + .setProjectUuid(project.uuid()); + } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/AlmSettingsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/AlmSettingsSupport.java index bbead0d9abf..f4e0812acdd 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/AlmSettingsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/AlmSettingsSupport.java @@ -33,7 +33,7 @@ import org.sonarqube.ws.AlmSettings; import static java.lang.String.format; import static org.sonar.api.web.UserRole.ADMIN; -class AlmSettingsSupport { +public class AlmSettingsSupport { private final DbClient dbClient; private final UserSession userSession; diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/SetAzureBindingAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/SetAzureBindingAction.java index 31b7e0e1db2..02cb4a17bdb 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/SetAzureBindingAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almsettings/SetAzureBindingAction.java @@ -73,7 +73,9 @@ public class SetAzureBindingAction implements AlmSettingsWsAction { AlmSettingDto almSettingDto = almSettingsSupport.getAlmSetting(dbSession, almSetting); dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, new ProjectAlmSettingDto() .setProjectUuid(project.uuid()) - .setAlmSettingUuid(almSettingDto.getUuid())); + .setAlmSettingUuid(almSettingDto.getUuid()) + .setAlmRepo(null) + .setAlmSlug(null)); 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 624dbadd03f..444283d3960 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 @@ -4,6 +4,11 @@ "key": "GitHub Server - Dev Team", "alm": "github", "url": "https://github.enterprise.com" + }, + { + "key": "Azure Server - Dev Team", + "alm": "azure", + "url": "https://azure.com" } ] } diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almsettings/list_definitions-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almsettings/list_definitions-example.json index aedb00599c1..f565a04acb6 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almsettings/list_definitions-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/almsettings/list_definitions-example.json @@ -12,5 +12,12 @@ "key": "Azure Devops Server - Dev Team", "personalAccessToken": "12345" } + ], + "bitbucket": [ + { + "key": "Bitbucket Server - Dev Team", + "url": "https://bitbucket.enterprise.com", + "personalAccessToken": "abcdef" + } ] } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/CountBindingActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/CountBindingActionTest.java index 8ea3c03fc45..6ff8b658bdb 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/CountBindingActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/CountBindingActionTest.java @@ -52,23 +52,39 @@ public class CountBindingActionTest { new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null)))); @Test - public void count_binding() { + public void count_github_binding() { UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); - AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting(); + AlmSettingDto almSetting = db.almSettings().insertGitHubAlmSetting(); ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); - db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project1); - db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project2); + db.almSettings().insertGitHubProjectAlmSetting(almSetting, project1); + db.almSettings().insertGitHubProjectAlmSetting(almSetting, project2); CountBindingWsResponse response = ws.newRequest() - .setParam("almSetting", githubAlmSetting.getKey()) + .setParam("almSetting", almSetting.getKey()) .executeProtobuf(CountBindingWsResponse.class); - assertThat(response.getKey()).isEqualTo(githubAlmSetting.getKey()); + assertThat(response.getKey()).isEqualTo(almSetting.getKey()); assertThat(response.getProjects()).isEqualTo(2); } + @Test + public void count_azure_binding() { + UserDto user = db.users().insertUser(); + userSession.logIn(user).setSystemAdministrator(); + AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting(); + ComponentDto project1 = db.components().insertPrivateProject(); + db.almSettings().insertAzureProjectAlmSetting(almSetting, project1); + + CountBindingWsResponse response = ws.newRequest() + .setParam("almSetting", almSetting.getKey()) + .executeProtobuf(CountBindingWsResponse.class); + + assertThat(response.getKey()).isEqualTo(almSetting.getKey()); + assertThat(response.getProjects()).isEqualTo(1); + } + @Test public void fail_when_alm_setting_does_not_exist() { UserDto user = db.users().insertUser(); 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 8b59c81aa8b..54fe6fc39e7 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 @@ -55,7 +55,7 @@ public class GetBindingActionTest { private WsActionTester ws = new WsActionTester(new GetBindingAction(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null))); @Test - public void get_project_binding() { + public void get_github_project_binding() { UserDto user = db.users().insertUser(); ComponentDto project = db.components().insertPrivateProject(); userSession.logIn(user).addProjectPermission(ADMIN, project); @@ -72,6 +72,24 @@ public class GetBindingActionTest { assertThat(response.getUrl()).isEqualTo(githubAlmSetting.getUrl()); } + @Test + public void get_azure_project_binding() { + 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); + + 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.hasRepository()).isFalse(); + assertThat(response.hasUrl()).isFalse(); + } + @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 72baba18c4a..ca54685f6dc 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 @@ -61,16 +61,19 @@ public class ListActionTest { userSession.logIn(user).addProjectPermission(ADMIN, project); AlmSettingDto githubAlmSetting1 = db.almSettings().insertGitHubAlmSetting(); AlmSettingDto githubAlmSetting2 = db.almSettings().insertGitHubAlmSetting(); + AlmSettingDto azureAlmSetting = db.almSettings().insertAzureAlmSetting(); ListWsResponse response = ws.newRequest() .setParam("project", project.getKey()) .executeProtobuf(AlmSettings.ListWsResponse.class); assertThat(response.getAlmSettingsList()) - .extracting(AlmSetting::getAlm, AlmSetting::getKey, AlmSetting::getUrl) + .extracting(AlmSetting::getAlm, AlmSetting::getKey, AlmSetting::hasUrl, AlmSetting::getUrl) .containsExactlyInAnyOrder( - tuple(AlmSettings.Alm.github, githubAlmSetting1.getKey(), githubAlmSetting1.getUrl()), - tuple(AlmSettings.Alm.github, githubAlmSetting2.getKey(), githubAlmSetting2.getUrl())); + 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, "") + ); } @Test @@ -115,6 +118,12 @@ public class ListActionTest { .setAppId("12345") .setPrivateKey("54684654")); 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")); + db.almSettings().insertAzureProjectAlmSetting(azureAlmSetting, project); String response = ws.newRequest() .setParam("project", project.getKey()) @@ -129,6 +138,7 @@ public class ListActionTest { assertThat(def.since()).isEqualTo("8.1"); assertThat(def.isPost()).isFalse(); + assertThat(def.responseExampleAsString()).isNotEmpty(); assertThat(def.params()) .extracting(WebService.Param::key, WebService.Param::isRequired) .containsExactlyInAnyOrder(tuple("project", true)); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ListDefinitionsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ListDefinitionsActionTest.java index d97d31af8ed..a32b074a3f3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ListDefinitionsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ListDefinitionsActionTest.java @@ -96,11 +96,16 @@ public class ListDefinitionsActionTest { .setUrl("https://github.enterprise.com") .setAppId("12345") .setPrivateKey("54684654")); - db.almSettings().insertAzureAlmSetting( a -> a.setKey("Azure Devops Server - Dev Team") .setPersonalAccessToken("12345") ); + db.almSettings().insertBitbucketAlmSetting( + a -> a.setKey("Bitbucket Server - Dev Team") + .setUrl("https://bitbucket.enterprise.com") + .setPersonalAccessToken("abcdef") + ); + String response = ws.newRequest().execute().getInput(); assertJson(response).isSimilarTo(getClass().getResource("list_definitions-example.json")); @@ -113,5 +118,6 @@ public class ListDefinitionsActionTest { assertThat(def.since()).isEqualTo("8.1"); assertThat(def.params()).isEmpty(); assertThat(def.isPost()).isFalse(); + assertThat(def.responseExampleAsString()).isNotEmpty(); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/SetAzureBindingActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/SetAzureBindingActionTest.java new file mode 100644 index 00000000000..b20f83fd86d --- /dev/null +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/SetAzureBindingActionTest.java @@ -0,0 +1,147 @@ +/* + * 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 SetAzureBindingActionTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + @Rule + public UserSessionRule userSession = UserSessionRule.standalone(); + @Rule + public DbTester db = DbTester.create(); + + private WsActionTester ws = new WsActionTester(new SetAzureBindingAction(db.getDbClient(), + new AlmSettingsSupport(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), null)))); + + @Test + public void set_azure_project_binding() { + UserDto user = db.users().insertUser(); + AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting(); + ComponentDto project = db.components().insertPrivateProject(); + userSession.logIn(user).addProjectPermission(ADMIN, project); + + ws.newRequest() + .setParam("almSetting", almSetting.getKey()) + .setParam("project", project.getKey()) + .execute(); + + assertThat(db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), project).get()) + .extracting(ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid, ProjectAlmSettingDto::getAlmRepo, ProjectAlmSettingDto::getAlmSlug) + .containsOnly(almSetting.getUuid(), project.uuid(), null, null); + } + + @Test + public void override_existing_azure_project_binding() { + UserDto user = db.users().insertUser(); + AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting(); + ComponentDto project = db.components().insertPrivateProject(); + db.almSettings().insertAzureProjectAlmSetting(almSetting, project); + AlmSettingDto anotherAlmSetting = db.almSettings().insertAzureAlmSetting(); + userSession.logIn(user).addProjectPermission(ADMIN, project); + + ws.newRequest() + .setParam("almSetting", anotherAlmSetting.getKey()) + .setParam("project", project.getKey()) + .execute(); + + assertThat(db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), project).get()) + .extracting(ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid, ProjectAlmSettingDto::getAlmRepo, ProjectAlmSettingDto::getAlmSlug) + .containsOnly(anotherAlmSetting.getUuid(), project.uuid(), null, null); + } + + @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()) + .execute(); + } + + @Test + public void fail_when_project_does_not_exist() { + UserDto user = db.users().insertUser(); + AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting(); + ComponentDto project = db.components().insertPrivateProject(); + userSession.logIn(user).addProjectPermission(ADMIN, project); + + expectedException.expect(NotFoundException.class); + + ws.newRequest() + .setParam("almSetting", almSetting.getKey()) + .setParam("project", "unknown") + .execute(); + } + + @Test + public void fail_when_missing_administer_permission_on_project() { + UserDto user = db.users().insertUser(); + AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting(); + 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()) + .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)); + } + +} 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 b461504d061..b99978ec45e 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 @@ -107,7 +107,6 @@ 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) @@ -125,7 +124,7 @@ public class AlmSettingsService extends BaseService { * @see Further information about this action online (including a response example) * @since 8.1 */ - public AlmSettings.GetBindingWsResponse getBinding(GetGithubBindingRequest request) { + public AlmSettings.GetBindingWsResponse getBinding(GetBindingRequest request) { return call( new GetRequest(path("get_binding")) .setParam("project", request.getProject()) @@ -158,6 +157,19 @@ public class AlmSettingsService extends BaseService { AlmSettings.ListDefinitionsWsResponse.parser()); } + /** + * This is a POST request. + * @see Further information about this action online (including a response example) + * @since 8.1 + */ + public void setAzureBinding(SetAzureBindingRequest request) { + call( + new PostRequest(path("set_azure_binding")) + .setParam("almSetting", request.getAlmSetting()) + .setParam("project", request.getProject()) + .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/GetGithubBindingRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/GetBindingRequest.java similarity index 93% rename from sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/GetGithubBindingRequest.java rename to sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/GetBindingRequest.java index d38e17c58ec..8fa19844e9c 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/GetGithubBindingRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/GetBindingRequest.java @@ -28,14 +28,14 @@ import javax.annotation.Generated; * @since 8.1 */ @Generated("sonar-ws-generator") -public class GetGithubBindingRequest { +public class GetBindingRequest { private String project; /** * This is a mandatory parameter. */ - public GetGithubBindingRequest setProject(String project) { + public GetBindingRequest setProject(String project) { this.project = project; return this; } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/SetAzureBindingRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/SetAzureBindingRequest.java new file mode 100644 index 00000000000..ecdbedd8024 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/almsettings/SetAzureBindingRequest.java @@ -0,0 +1,59 @@ +/* + * 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 SetAzureBindingRequest { + + private String almSetting; + private String project; + + /** + * This is a mandatory parameter. + */ + public SetAzureBindingRequest setAlmSetting(String almSetting) { + this.almSetting = almSetting; + return this; + } + + public String getAlmSetting() { + return almSetting; + } + + /** + * This is a mandatory parameter. + */ + public SetAzureBindingRequest setProject(String project) { + this.project = project; + return this; + } + + public String getProject() { + return project; + } + +} -- 2.39.5