import java.util.Arrays;
import org.sonar.api.server.ws.WebService;
+import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.CONTROLLER;
+
public class BranchesWs implements WebService {
private final BranchWsAction[] actions;
@Override
public void define(Context context) {
- NewController controller = context.createController("api/project_branches")
+ NewController controller = context.createController(CONTROLLER)
.setSince("6.6");
Arrays.stream(actions).forEach(action -> action.define(controller));
controller.done();
import static org.sonar.core.util.Protobuf.setNullable;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
+import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.ACTION_LIST;
+import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.PARAM_PROJECT;
public class ListAction implements BranchWsAction {
- private static final String PROJECT_PARAM = "project";
-
private final DbClient dbClient;
private final UserSession userSession;
@Override
public void define(WebService.NewController context) {
- WebService.NewAction action = context.createAction("list")
+ WebService.NewAction action = context.createAction(ACTION_LIST)
.setSince("6.6")
.setDescription("List the branches of a project")
.setResponseExample(Resources.getResource(getClass(), "list-example.json"))
.setHandler(this);
action
- .createParam(PROJECT_PARAM)
+ .createParam(PARAM_PROJECT)
.setDescription("Project key")
.setExampleValue(KEY_PROJECT_EXAMPLE_001)
.setRequired(true);
@Override
public void handle(Request request, Response response) throws Exception {
- String projectKey = request.mandatoryParam(PROJECT_PARAM);
+ String projectKey = request.mandatoryParam(PARAM_PROJECT);
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto project = dbClient.componentDao().selectOrFailByKey(dbSession, projectKey);
import org.sonarqube.ws.client.permission.PermissionsService;
import org.sonarqube.ws.client.project.ProjectsService;
import org.sonarqube.ws.client.projectanalysis.ProjectAnalysisService;
+import org.sonarqube.ws.client.projectbranches.ProjectBranchesService;
import org.sonarqube.ws.client.projectlinks.ProjectLinksService;
import org.sonarqube.ws.client.qualitygate.QualityGatesService;
import org.sonarqube.ws.client.qualityprofile.QualityProfilesService;
private final RootsService rootsService;
private final WebhooksService webhooksService;
private final ProjectAnalysisService projectAnalysisService;
+ private final ProjectBranchesService projectBranchesService;
DefaultWsClient(WsConnector wsConnector) {
this.wsConnector = wsConnector;
this.rootsService = new RootsService(wsConnector);
this.webhooksService = new WebhooksService(wsConnector);
this.projectAnalysisService = new ProjectAnalysisService(wsConnector);
+ this.projectBranchesService = new ProjectBranchesService(wsConnector);
}
@Override
public ProjectAnalysisService projectAnalysis() {
return projectAnalysisService;
}
+
+ @Override
+ public ProjectBranchesService projectBranches() {
+ return projectBranchesService;
+ }
}
import org.sonarqube.ws.client.permission.PermissionsService;
import org.sonarqube.ws.client.project.ProjectsService;
import org.sonarqube.ws.client.projectanalysis.ProjectAnalysisService;
+import org.sonarqube.ws.client.projectbranches.ProjectBranchesService;
import org.sonarqube.ws.client.projectlinks.ProjectLinksService;
import org.sonarqube.ws.client.qualitygate.QualityGatesService;
import org.sonarqube.ws.client.qualityprofile.QualityProfilesService;
* @since 6.3
*/
ProjectAnalysisService projectAnalysis();
+
+ /**
+ * @since 6.6>
+ */
+ ProjectBranchesService projectBranches();
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.projectbranches;
+
+public class ProjectBranchesParameters {
+
+ public static final String CONTROLLER = "api/project_branches";
+
+ // actions
+ public static final String ACTION_LIST = "list";
+
+ // parameters
+ public static final String PARAM_PROJECT = "project";
+
+ private ProjectBranchesParameters() {
+ // static utility class
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.projectbranches;
+
+import org.sonarqube.ws.WsBranches.ListWsResponse;
+import org.sonarqube.ws.client.BaseService;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.WsConnector;
+
+import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.ACTION_LIST;
+import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.CONTROLLER;
+import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.PARAM_PROJECT;
+
+public class ProjectBranchesService extends BaseService {
+
+ public ProjectBranchesService(WsConnector wsConnector) {
+ super(wsConnector, CONTROLLER);
+ }
+
+ public ListWsResponse list(String project) {
+ GetRequest get = new GetRequest(path(ACTION_LIST))
+ .setParam(PARAM_PROJECT, project);
+ return call(get, ListWsResponse.parser());
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonarqube.ws.client.projectbranches;
+
+import javax.annotation.ParametersAreNonnullByDefault;
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.projectbranches;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.ws.WsBranches.ListWsResponse;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.ServiceTester;
+import org.sonarqube.ws.client.WsConnector;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.PARAM_PROJECT;
+
+public class ProjectBranchesServiceTest {
+
+ @Rule
+ public ServiceTester<ProjectBranchesService> serviceTester = new ServiceTester<>(new ProjectBranchesService(mock(WsConnector.class)));
+
+ private ProjectBranchesService underTest = serviceTester.getInstanceUnderTest();
+
+ @Test
+ public void list() {
+ underTest.list("projectKey");
+
+ assertThat(serviceTester.getGetParser()).isSameAs(ListWsResponse.parser());
+
+ GetRequest getRequest = serviceTester.getGetRequest();
+ serviceTester.assertThat(getRequest)
+ .hasPath("list")
+ .hasParam(PARAM_PROJECT, "projectKey")
+ .andNoOtherParam();
+ }
+
+}