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;
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);
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();
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));
.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);
}
}
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) {
"branches": [
{
"name": "feature/bar",
- "project": "sonarqube",
"isMain": false,
"type": "LONG"
},
{
"name": "feature/foo",
- "project": "sonarqube",
"isMain": false,
"type": "SHORT",
"mergeBranch": "feature/bar"
{
"branch": {
"name": "feature/bar",
- "project": "sonarqube",
"isMain": false,
"type": "LONG"
}
.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
.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
.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
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