aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-08-16 10:15:04 +0200
committerJanos Gyerik <janos.gyerik@sonarsource.com>2017-09-12 10:59:56 +0200
commit2666f225879148e335913d1ea4247c33397961e8 (patch)
tree02a39064503e0edb1b228f49d8c935e2c8effd9d
parent6affc4080d8b98d499174f64e2c86c84cbd2872d (diff)
downloadsonarqube-2666f225879148e335913d1ea4247c33397961e8.tar.gz
sonarqube-2666f225879148e335913d1ea4247c33397961e8.zip
SONAR-9616 Do not return project in api/projectbranches ws
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ShowAction.java6
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/projectbranch/ws/list-example.json2
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/projectbranch/ws/show-example.json1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/projectbranch/ws/ShowActionTest.java12
-rw-r--r--sonar-ws/src/main/protobuf/ws-projectbranches.proto9
6 files changed, 16 insertions, 22 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java
index 211799777a0..3fe1052e356 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java
@@ -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();
diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ShowAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ShowAction.java
index 0129706d379..1bcaaf4ba82 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ShowAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ShowAction.java
@@ -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) {
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/projectbranch/ws/list-example.json b/server/sonar-server/src/main/resources/org/sonar/server/projectbranch/ws/list-example.json
index f9f9ab6991e..0078ef5f40b 100644
--- a/server/sonar-server/src/main/resources/org/sonar/server/projectbranch/ws/list-example.json
+++ b/server/sonar-server/src/main/resources/org/sonar/server/projectbranch/ws/list-example.json
@@ -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"
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/projectbranch/ws/show-example.json b/server/sonar-server/src/main/resources/org/sonar/server/projectbranch/ws/show-example.json
index 857822f4b6f..b6ab6821032 100644
--- a/server/sonar-server/src/main/resources/org/sonar/server/projectbranch/ws/show-example.json
+++ b/server/sonar-server/src/main/resources/org/sonar/server/projectbranch/ws/show-example.json
@@ -1,7 +1,6 @@
{
"branch": {
"name": "feature/bar",
- "project": "sonarqube",
"isMain": false,
"type": "LONG"
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/projectbranch/ws/ShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/projectbranch/ws/ShowActionTest.java
index e37116f1fcf..e2d48dc024a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/projectbranch/ws/ShowActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/projectbranch/ws/ShowActionTest.java
@@ -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
diff --git a/sonar-ws/src/main/protobuf/ws-projectbranches.proto b/sonar-ws/src/main/protobuf/ws-projectbranches.proto
index 8054febfafc..4500dc5a784 100644
--- a/sonar-ws/src/main/protobuf/ws-projectbranches.proto
+++ b/sonar-ws/src/main/protobuf/ws-projectbranches.proto
@@ -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