]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9616 Do not return project in api/projectbranches ws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 16 Aug 2017 08:15:04 +0000 (10:15 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 08:59:56 +0000 (10:59 +0200)
server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java
server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ShowAction.java
server/sonar-server/src/main/resources/org/sonar/server/projectbranch/ws/list-example.json
server/sonar-server/src/main/resources/org/sonar/server/projectbranch/ws/show-example.json
server/sonar-server/src/test/java/org/sonar/server/projectbranch/ws/ShowActionTest.java
sonar-ws/src/main/protobuf/ws-projectbranches.proto

index 211799777a0e3da9dede941e4afb294ecc01de48..3fe1052e356bffafed039dbcfd7a7d7acc7caebd 100644 (file)
@@ -56,6 +56,7 @@ import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex;
 import static org.sonar.db.component.BranchType.LONG;
 import static org.sonar.db.component.BranchType.SHORT;
 import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
+import static org.sonar.server.ws.WsUtils.checkFoundWithOptional;
 import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.ACTION_LIST;
 import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.PARAM_PROJECT;
 
@@ -90,7 +91,7 @@ public class ListAction implements BranchWsAction {
     String projectKey = request.mandatoryParam(PARAM_PROJECT);
 
     try (DbSession dbSession = dbClient.openSession(false)) {
-      ComponentDto project = WsUtils.checkFoundWithOptional(
+      ComponentDto project = checkFoundWithOptional(
         dbClient.componentDao().selectByKey(dbSession, projectKey),
         "Project key '%s' not found", projectKey);
 
@@ -112,16 +113,15 @@ public class ListAction implements BranchWsAction {
       WsBranches.ListWsResponse.Builder protobufResponse = WsBranches.ListWsResponse.newBuilder();
       branches.stream()
         .filter(b -> b.getKeeType().equals(BranchKeyType.BRANCH))
-        .forEach(b -> addToProtobuf(protobufResponse, b, project, mergeBranchesByUuid, metricIdsByKey, measuresByComponentUuids));
+        .forEach(b -> addToProtobuf(protobufResponse, b, mergeBranchesByUuid, metricIdsByKey, measuresByComponentUuids));
       WsUtils.writeProtobuf(protobufResponse.build(), request, response);
     }
   }
 
-  private static void addToProtobuf(WsBranches.ListWsResponse.Builder response, BranchDto branch, ComponentDto project, Map<String, BranchDto> mergeBranchesByUuid,
+  private static void addToProtobuf(WsBranches.ListWsResponse.Builder response, BranchDto branch, Map<String, BranchDto> mergeBranchesByUuid,
     Map<String, Integer> metricIdsByKey, Multimap<String, MeasureDto> measuresByComponentUuids) {
     WsBranches.Branch.Builder builder = response.addBranchesBuilder();
     setNullable(branch.getKey(), builder::setName);
-    builder.setProject(project.getKey());
     builder.setIsMain(branch.isMain());
     builder.setType(WsBranches.Branch.BranchType.valueOf(branch.getBranchType().name()));
     String mergeBranchUuid = branch.getMergeBranchUuid();
index 0129706d379789842b5417bcc76b4eb1f21eefed..1bcaaf4ba82f46babc6e40f5520b06e623ea0d1f 100644 (file)
@@ -103,7 +103,6 @@ public class ShowAction implements BranchWsAction {
     try (DbSession dbSession = dbClient.openSession(false)) {
       ComponentDto component = componentFinder.getByKeyAndBranch(dbSession, projectKey, branchName);
       userSession.checkComponentPermission(UserRole.USER, component);
-      ComponentDto project = componentFinder.getByUuid(dbSession, component.projectUuid());
 
       List<MetricDto> metrics = dbClient.metricDao().selectByKeys(dbSession, asList(ALERT_STATUS_KEY, BUGS_KEY, VULNERABILITIES_KEY, CODE_SMELLS_KEY));
       Map<Integer, MetricDto> metricsById = metrics.stream().collect(uniqueIndex(MetricDto::getId));
@@ -117,7 +116,7 @@ public class ShowAction implements BranchWsAction {
         .selectByComponentsAndMetrics(dbSession, Collections.singletonList(branch.getUuid()), metricsById.keySet())
         .stream().collect(index(MeasureDto::getComponentUuid));
 
-      WsUtils.writeProtobuf(buildResponse(branch, project, mergeBranch, metricIdsByKey, measuresByComponentUuids), request, response);
+      WsUtils.writeProtobuf(buildResponse(branch, mergeBranch, metricIdsByKey, measuresByComponentUuids), request, response);
     }
   }
 
@@ -127,11 +126,10 @@ public class ShowAction implements BranchWsAction {
     return branch.get();
   }
 
-  private static ShowWsResponse buildResponse(BranchDto branch, ComponentDto project, @Nullable BranchDto mergeBranch,
+  private static ShowWsResponse buildResponse(BranchDto branch, @Nullable BranchDto mergeBranch,
     Map<String, Integer> metricIdsByKey, Multimap<String, MeasureDto> measuresByComponentUuids) {
     WsBranches.Branch.Builder builder = WsBranches.Branch.newBuilder();
     setNullable(branch.getKey(), builder::setName);
-    builder.setProject(project.getKey());
     builder.setIsMain(branch.isMain());
     builder.setType(WsBranches.Branch.BranchType.valueOf(branch.getBranchType().name()));
     if (mergeBranch != null) {
index f9f9ab6991ee906f494b1fd01d0cd993e7dddbaa..0078ef5f40b5a1a3866c6a4895af98aa90574b9a 100644 (file)
@@ -2,13 +2,11 @@
   "branches": [
     {
       "name": "feature/bar",
-      "project": "sonarqube",
       "isMain": false,
       "type": "LONG"
     },
     {
       "name": "feature/foo",
-      "project": "sonarqube",
       "isMain": false,
       "type": "SHORT",
       "mergeBranch": "feature/bar"
index 857822f4b6f2c448ce65d58e5d56a70c59b76ac0..b6ab6821032ab9723dce34c007a82fa5d6437d47 100644 (file)
@@ -1,7 +1,6 @@
 {
   "branch": {
     "name": "feature/bar",
-    "project": "sonarqube",
     "isMain": false,
     "type": "LONG"
   }
index e37116f1fcfc640e5167f07c9c51ef42f20f1bfb..e2d48dc024a11afa4cc81b93f34ab3cb55310a79 100644 (file)
@@ -101,8 +101,8 @@ public class ShowActionTest {
       .executeProtobuf(ShowWsResponse.class);
 
     assertThat(response.getBranch())
-      .extracting(Branch::getName, Branch::getProject, Branch::getType, Branch::getMergeBranch)
-      .containsExactlyInAnyOrder(longLivingBranch.getBranch(), project.getKey(), Branch.BranchType.LONG, "");
+      .extracting(Branch::getName, Branch::getType, Branch::getMergeBranch)
+      .containsExactlyInAnyOrder(longLivingBranch.getBranch(), Branch.BranchType.LONG, "");
   }
 
   @Test
@@ -120,8 +120,8 @@ public class ShowActionTest {
       .executeProtobuf(ShowWsResponse.class);
 
     assertThat(response.getBranch())
-      .extracting(Branch::getName, Branch::getProject, Branch::getType, Branch::getMergeBranch)
-      .containsExactlyInAnyOrder(shortLivingBranch.getBranch(), project.getKey(), Branch.BranchType.SHORT, longLivingBranch.getBranch());
+      .extracting(Branch::getName, Branch::getType, Branch::getMergeBranch)
+      .containsExactlyInAnyOrder(shortLivingBranch.getBranch(), Branch.BranchType.SHORT, longLivingBranch.getBranch());
   }
 
   @Test
@@ -178,8 +178,8 @@ public class ShowActionTest {
       .executeProtobuf(ShowWsResponse.class);
 
     assertThat(response.getBranch())
-      .extracting(Branch::getName, Branch::getProject, Branch::getType, Branch::getMergeBranch)
-      .containsExactlyInAnyOrder(file.getBranch(), project.getKey(), Branch.BranchType.LONG, "");
+      .extracting(Branch::getName, Branch::getType, Branch::getMergeBranch)
+      .containsExactlyInAnyOrder(file.getBranch(), Branch.BranchType.LONG, "");
   }
 
   @Test
index 8054febfafc4614f692821de9c9e0d762cd599bc..4500dc5a784fc48cfc2f650045bb056438e3b598 100644 (file)
@@ -37,12 +37,11 @@ message ShowWsResponse {
 
 message Branch {
   optional string name = 1;
-  optional string project = 2;
-  optional bool isMain = 3;
-  optional BranchType type = 4;
+  optional bool isMain = 2;
+  optional BranchType type = 3;
   // Merge branch is only present for short living branch
-  optional string mergeBranch = 5;
-  optional Status status = 6;
+  optional string mergeBranch = 4;
+  optional Status status = 5;
 
   message Status {
     // Quality gate status is only present for long living branch