--- /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.sonar.server.projectbranch.ws;
+
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.sonar.db.component.BranchDto;
+import org.sonar.db.measure.MeasureDto;
+import org.sonarqube.ws.Common;
+import org.sonarqube.ws.WsBranches;
+
+import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY;
+import static org.sonar.api.measures.CoreMetrics.BUGS_KEY;
+import static org.sonar.api.measures.CoreMetrics.CODE_SMELLS_KEY;
+import static org.sonar.api.measures.CoreMetrics.VULNERABILITIES_KEY;
+import static org.sonar.core.util.Protobuf.setNullable;
+import static org.sonar.db.component.BranchType.LONG;
+import static org.sonar.db.component.BranchType.SHORT;
+import static org.sonar.server.projectbranch.ws.BranchesWs.DEFAULT_MAIN_BRANCH_NAME;
+
+public class BranchDtoToWsBranch {
+
+ private BranchDtoToWsBranch() {
+ // static methods only
+ }
+
+ public static WsBranches.Branch.Builder toBranchBuilder(BranchDto branch, @Nullable BranchDto mergeBranch, Map<String, MeasureDto> measuresByMetricKey) {
+ WsBranches.Branch.Builder builder = WsBranches.Branch.newBuilder();
+ String branchKey = branch.getKey();
+ String effectiveBranchKey = branchKey == null && branch.isMain() ? DEFAULT_MAIN_BRANCH_NAME : branchKey;
+ setNullable(effectiveBranchKey, builder::setName);
+ builder.setIsMain(branch.isMain());
+ builder.setType(Common.BranchType.valueOf(branch.getBranchType().name()));
+ if (mergeBranch != null) {
+ String mergeBranchKey = mergeBranch.getKey();
+ if (mergeBranchKey == null && branch.getBranchType().equals(SHORT)) {
+ builder.setMergeBranch(DEFAULT_MAIN_BRANCH_NAME);
+ } else {
+ setNullable(mergeBranchKey, builder::setMergeBranch);
+ }
+ }
+
+ if (branch.getBranchType().equals(LONG)) {
+ WsBranches.Branch.Status.Builder statusBuilder = WsBranches.Branch.Status.newBuilder();
+ MeasureDto measure = measuresByMetricKey.get(ALERT_STATUS_KEY);
+ setNullable(measure, m -> builder.setStatus(statusBuilder.setQualityGateStatus(m.getData())));
+ }
+
+ if (branch.getBranchType().equals(SHORT)) {
+ WsBranches.Branch.Status.Builder statusBuilder = WsBranches.Branch.Status.newBuilder();
+ MeasureDto bugs = measuresByMetricKey.get(BUGS_KEY);
+ setNullable(bugs, m -> builder.setStatus(statusBuilder.setBugs(m.getValue().intValue())));
+
+ MeasureDto vulnerabilities = measuresByMetricKey.get(VULNERABILITIES_KEY);
+ setNullable(vulnerabilities, m -> builder.setStatus(statusBuilder.setVulnerabilities(m.getValue().intValue())));
+
+ MeasureDto codeSmells = measuresByMetricKey.get(CODE_SMELLS_KEY);
+ setNullable(codeSmells, m -> builder.setStatus(statusBuilder.setCodeSmells(m.getValue().intValue())));
+ builder.setStatus(statusBuilder);
+ }
+ return builder;
+ }
+}
public class BranchesWs implements WebService {
+ public static final String DEFAULT_MAIN_BRANCH_NAME = "master";
+
private final BranchWsAction[] actions;
public BranchesWs(BranchWsAction... actions) {
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.function.Function;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.server.user.UserSession;
import org.sonar.server.ws.WsUtils;
import org.sonarqube.ws.WsBranches;
-import org.sonarqube.ws.WsBranches.Branch.Status;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static org.sonar.api.measures.CoreMetrics.CODE_SMELLS_KEY;
import static org.sonar.api.measures.CoreMetrics.VULNERABILITIES_KEY;
import static org.sonar.api.resources.Qualifiers.PROJECT;
-import static org.sonar.core.util.Protobuf.setNullable;
import static org.sonar.core.util.stream.MoreCollectors.index;
import static org.sonar.core.util.stream.MoreCollectors.toList;
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.projectbranch.ws.BranchDtoToWsBranch.toBranchBuilder;
import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001;
-import static org.sonarqube.ws.Common.BranchType;
import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.ACTION_LIST;
import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.PARAM_PROJECT;
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));
- Map<String, Integer> metricIdsByKey = metrics.stream().collect(uniqueIndex(MetricDto::getKey, MetricDto::getId));
Collection<BranchDto> branches = dbClient.branchDao().selectByComponent(dbSession, project);
Map<String, BranchDto> mergeBranchesByUuid = dbClient.branchDao()
WsBranches.ListWsResponse.Builder protobufResponse = WsBranches.ListWsResponse.newBuilder();
branches.stream()
.filter(b -> b.getKeeType().equals(BranchKeyType.BRANCH))
- .forEach(b -> addToProtobuf(protobufResponse, b, mergeBranchesByUuid, metricIdsByKey, measuresByComponentUuids));
+ .forEach(b -> addBranch(protobufResponse, b, mergeBranchesByUuid, metricsById, measuresByComponentUuids.get(b.getUuid())));
WsUtils.writeProtobuf(protobufResponse.build(), request, response);
}
}
- 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.setIsMain(branch.isMain());
- builder.setType(BranchType.valueOf(branch.getBranchType().name()));
+ private static void addBranch(WsBranches.ListWsResponse.Builder response, BranchDto branch, Map<String, BranchDto> mergeBranchesByUuid,
+ Map<Integer, MetricDto> metricsById, Collection<MeasureDto> measures) {
+
+ BranchDto mergeBranch = null;
String mergeBranchUuid = branch.getMergeBranchUuid();
if (mergeBranchUuid != null) {
- BranchDto mergeBranch = mergeBranchesByUuid.get(mergeBranchUuid);
+ mergeBranch = mergeBranchesByUuid.get(mergeBranchUuid);
checkState(mergeBranch != null, "Component uuid '%s' cannot be found", mergeBranch);
- setNullable(mergeBranch.getKey(), builder::setMergeBranch);
- }
-
- Collection<MeasureDto> componentMeasures = measuresByComponentUuids.get(branch.getUuid());
- if (branch.getBranchType().equals(LONG)) {
- Status.Builder statusBuilder = Status.newBuilder();
- int qualityGateStatusMetricId = metricIdsByKey.get(ALERT_STATUS_KEY);
- componentMeasures.stream().filter(m -> m.getMetricId() == qualityGateStatusMetricId).findAny()
- .ifPresent(measure -> builder.setStatus(statusBuilder.setQualityGateStatus(measure.getData())));
- }
-
- if (branch.getBranchType().equals(SHORT)) {
- Status.Builder statusBuilder = Status.newBuilder();
- int bugsMetricId = metricIdsByKey.get(BUGS_KEY);
- componentMeasures.stream().filter(m -> m.getMetricId() == bugsMetricId).findAny()
- .ifPresent(measure -> statusBuilder.setBugs(measure.getValue().intValue()));
-
- int vulnerabilitiesMetricId = metricIdsByKey.get(VULNERABILITIES_KEY);
- componentMeasures.stream().filter(m -> m.getMetricId() == vulnerabilitiesMetricId).findAny()
- .ifPresent(measure -> statusBuilder.setVulnerabilities(measure.getValue().intValue()));
-
- int codeSmellMetricId = metricIdsByKey.get(CODE_SMELLS_KEY);
- componentMeasures.stream().filter(m -> m.getMetricId() == codeSmellMetricId).findAny()
- .ifPresent(measure -> statusBuilder.setCodeSmells(measure.getValue().intValue()));
- builder.setStatus(statusBuilder);
}
- builder.build();
+ response.addBranches(
+ toBranchBuilder(branch, mergeBranch,
+ measures.stream().collect(uniqueIndex(m -> metricsById.get(m.getMetricId()).getKey(), Function.identity()))));
}
}
*/
package org.sonar.server.projectbranch.ws;
-import com.google.common.collect.Multimap;
import com.google.common.io.Resources;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.function.Function;
import javax.annotation.Nullable;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.computation.task.projectanalysis.analysis.Branch;
import org.sonar.server.user.UserSession;
-import org.sonar.server.ws.WsUtils;
import org.sonarqube.ws.WsBranches;
-import org.sonarqube.ws.WsBranches.Branch.Status;
import org.sonarqube.ws.WsBranches.ShowWsResponse;
import static com.google.common.base.Preconditions.checkState;
import static org.sonar.api.measures.CoreMetrics.BUGS_KEY;
import static org.sonar.api.measures.CoreMetrics.CODE_SMELLS_KEY;
import static org.sonar.api.measures.CoreMetrics.VULNERABILITIES_KEY;
-import static org.sonar.core.util.Protobuf.setNullable;
import static org.sonar.core.util.stream.MoreCollectors.index;
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.projectbranch.ws.BranchDtoToWsBranch.toBranchBuilder;
import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001;
import static org.sonar.server.ws.KeyExamples.KEY_FILE_EXAMPLE_001;
-import static org.sonarqube.ws.Common.BranchType;
+import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.ACTION_SHOW;
import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.PARAM_BRANCH;
import static org.sonarqube.ws.client.projectbranches.ProjectBranchesParameters.PARAM_COMPONENT;
@Override
public void handle(Request request, Response response) throws Exception {
if (!isBranchFeatureSupported) {
- WsUtils.writeProtobuf(WsBranches.Branch.newBuilder().build(), request, response);
+ writeProtobuf(WsBranches.Branch.newBuilder().build(), request, response);
return;
}
String projectKey = request.mandatoryParam(PARAM_COMPONENT);
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));
- Map<String, Integer> metricIdsByKey = metrics.stream().collect(uniqueIndex(MetricDto::getKey, MetricDto::getId));
BranchDto branch = getBranch(dbSession, component.projectUuid());
String mergeBranchUuid = branch.getMergeBranchUuid();
BranchDto mergeBranch = mergeBranchUuid == null ? null : getBranch(dbSession, mergeBranchUuid);
- Multimap<String, MeasureDto> measuresByComponentUuids = dbClient.measureDao()
+ Collection<MeasureDto> measures = dbClient.measureDao()
.selectByComponentsAndMetrics(dbSession, Collections.singletonList(branch.getUuid()), metricsById.keySet())
- .stream().collect(index(MeasureDto::getComponentUuid));
+ .stream().collect(index(MeasureDto::getComponentUuid))
+ .get(branch.getUuid());
- WsUtils.writeProtobuf(buildResponse(branch, mergeBranch, metricIdsByKey, measuresByComponentUuids), request, response);
+ writeProtobuf(ShowWsResponse.newBuilder()
+ .setBranch(
+ toBranchBuilder(branch, mergeBranch, measures.stream().collect(uniqueIndex(m -> metricsById.get(m.getMetricId()).getKey(), Function.identity()))))
+ .build(), request, response);
}
}
return branch.get();
}
- 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.setIsMain(branch.isMain());
- builder.setType(BranchType.valueOf(branch.getBranchType().name()));
- if (mergeBranch != null) {
- setNullable(mergeBranch.getKey(), builder::setMergeBranch);
- }
-
- Status.Builder statusBuilder = Status.newBuilder();
- Collection<MeasureDto> componentMeasures = measuresByComponentUuids.get(branch.getUuid());
- if (branch.getBranchType().equals(LONG)) {
- int qualityGateStatusMetricId = metricIdsByKey.get(ALERT_STATUS_KEY);
- componentMeasures.stream().filter(m -> m.getMetricId() == qualityGateStatusMetricId).findAny()
- .ifPresent(measure -> statusBuilder.setQualityGateStatus(measure.getData()));
- }
-
- if (branch.getBranchType().equals(SHORT)) {
- int bugsMetricId = metricIdsByKey.get(BUGS_KEY);
- componentMeasures.stream().filter(m -> m.getMetricId() == bugsMetricId).findAny()
- .ifPresent(measure -> statusBuilder.setBugs(measure.getValue().intValue()));
-
- int vulnerabilitiesMetricId = metricIdsByKey.get(VULNERABILITIES_KEY);
- componentMeasures.stream().filter(m -> m.getMetricId() == vulnerabilitiesMetricId).findAny()
- .ifPresent(measure -> statusBuilder.setVulnerabilities(measure.getValue().intValue()));
-
- int codeSmellMetricId = metricIdsByKey.get(CODE_SMELLS_KEY);
- componentMeasures.stream().filter(m -> m.getMetricId() == codeSmellMetricId).findAny()
- .ifPresent(measure -> statusBuilder.setCodeSmells(measure.getValue().intValue()));
- }
-
- builder.setStatus(statusBuilder);
- return ShowWsResponse.newBuilder().setBranch(builder).build();
- }
-
}
private MetricDto vulnerabilities;
private MetricDto codeSmells;
- public WsActionTester tester = new WsActionTester(new ListAction(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), resourceTypes)));
+ public WsActionTester ws = new WsActionTester(new ListAction(db.getDbClient(), userSession, new ComponentFinder(db.getDbClient(), resourceTypes)));
@Before
public void setUp() throws Exception {
@Test
public void test_definition() {
- WebService.Action definition = tester.getDef();
+ WebService.Action definition = ws.getDef();
assertThat(definition.key()).isEqualTo("list");
assertThat(definition.isPost()).isFalse();
assertThat(definition.isInternal()).isTrue();
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("The 'project' parameter is missing");
- tester.newRequest().execute();
+ ws.newRequest().execute();
}
@Test
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Invalid project key");
- tester.newRequest()
+ ws.newRequest()
.setParam("project", file.getDbKey())
.execute();
}
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Component key 'foo' not found");
- tester.newRequest()
+ ws.newRequest()
.setParam("project", "foo")
.execute();
}
ComponentDto project = db.components().insertMainBranch();
userSession.logIn().addProjectPermission(UserRole.USER, project);
- ListWsResponse response = tester.newRequest()
+ ListWsResponse response = ws.newRequest()
.setParam("project", project.getDbKey())
.executeProtobuf(ListWsResponse.class);
assertThat(response.getBranchesList())
- .extracting(Branch::hasName, Branch::getIsMain, Branch::getType)
- .containsExactlyInAnyOrder(tuple(false, true, Common.BranchType.LONG));
+ .extracting(Branch::getName, Branch::getIsMain, Branch::getType)
+ .containsExactlyInAnyOrder(tuple("master", true, Common.BranchType.LONG));
+ }
+
+ @Test
+ public void main_branch_with_specified_name() {
+ OrganizationDto organization = db.organizations().insert();
+ ComponentDto project = db.components().insertMainBranch(organization, "head");
+ userSession.logIn().addProjectPermission(UserRole.USER, project);
+
+ ListWsResponse response = ws.newRequest()
+ .setParam("project", project.getDbKey())
+ .executeProtobuf(ListWsResponse.class);
+
+ assertThat(response.getBranchesList())
+ .extracting(Branch::getName, Branch::getIsMain, Branch::getType)
+ .containsExactlyInAnyOrder(tuple("head", true, Common.BranchType.LONG));
}
@Test
ComponentDto project = db.components().insertPrivateProject();
userSession.logIn().addProjectPermission(UserRole.USER, project);
- String json = tester.newRequest()
+ String json = ws.newRequest()
.setParam("project", project.getDbKey())
.setMediaType(MediaTypes.JSON)
.execute()
db.components().insertProjectBranch(project, b -> b.setKey("feature/foo"));
userSession.logIn().addProjectPermission(UserRole.USER, project);
- ListWsResponse response = tester.newRequest()
+ ListWsResponse response = ws.newRequest()
.setParam("project", project.getDbKey())
.executeProtobuf(ListWsResponse.class);
assertThat(response.getBranchesList())
.extracting(Branch::getName, Branch::getType)
.containsExactlyInAnyOrder(
- tuple("", Common.BranchType.LONG),
+ tuple("master", Common.BranchType.LONG),
tuple("feature/foo", Common.BranchType.LONG),
tuple("feature/bar", Common.BranchType.LONG));
}
ComponentDto shortLivingBranchOnMaster = db.components().insertProjectBranch(project,
b -> b.setKey("short_on_master").setBranchType(BranchType.SHORT).setMergeBranchUuid(project.uuid()));
- ListWsResponse response = tester.newRequest()
+ ListWsResponse response = ws.newRequest()
.setParam("project", project.getKey())
.executeProtobuf(ListWsResponse.class);
assertThat(response.getBranchesList())
.extracting(Branch::getName, Branch::getType, Branch::getMergeBranch)
.containsExactlyInAnyOrder(
- tuple("", Common.BranchType.LONG, ""),
+ tuple("master", Common.BranchType.LONG, ""),
tuple(longLivingBranch.getBranch(), Common.BranchType.LONG, ""),
tuple(shortLivingBranch.getBranch(), Common.BranchType.SHORT, longLivingBranch.getBranch()),
- tuple(shortLivingBranchOnMaster.getBranch(), Common.BranchType.SHORT, ""));
+ tuple(shortLivingBranchOnMaster.getBranch(), Common.BranchType.SHORT, "master"));
+ }
+
+ @Test
+ public void mergeBranch_is_using_default_main_name_when_main_branch_has_no_name() {
+ ComponentDto project = db.components().insertMainBranch();
+ userSession.logIn().addProjectPermission(UserRole.USER, project);
+ ComponentDto shortLivingBranch = db.components().insertProjectBranch(project,
+ b -> b.setKey("short").setBranchType(BranchType.SHORT).setMergeBranchUuid(project.uuid()));
+
+ WsBranches.ShowWsResponse response = ws.newRequest()
+ .setParam("project", shortLivingBranch.getKey())
+ .executeProtobuf(WsBranches.ShowWsResponse.class);
+
+ assertThat(response.getBranch())
+ .extracting(Branch::getName, Branch::getType, Branch::getMergeBranch)
+ .containsExactlyInAnyOrder(shortLivingBranch.getBranch(), Common.BranchType.SHORT, "master");
}
@Test
SnapshotDto branchAnalysis = db.components().insertSnapshot(branch);
db.measures().insertMeasure(branch, branchAnalysis, qualityGateStatus, m -> m.setData("OK"));
- ListWsResponse response = tester.newRequest()
+ ListWsResponse response = ws.newRequest()
.setParam("project", project.getKey())
.executeProtobuf(ListWsResponse.class);
db.measures().insertMeasure(shortLivingBranch, branchAnalysis, vulnerabilities, m -> m.setValue(2d));
db.measures().insertMeasure(shortLivingBranch, branchAnalysis, codeSmells, m -> m.setValue(3d));
- ListWsResponse response = tester.newRequest()
+ ListWsResponse response = ws.newRequest()
.setParam("project", project.getKey())
.executeProtobuf(ListWsResponse.class);
expectedException.expect(NotFoundException.class);
expectedException.expectMessage(format("Component key '%s' not found", branch.getDbKey()));
- tester.newRequest()
+ ws.newRequest()
.setParam("project", branch.getDbKey())
.execute();
}
db.components().insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(BranchType.SHORT).setMergeBranchUuid(longLivingBranch.uuid()));
userSession.logIn().addProjectPermission(UserRole.USER, project);
- String json = tester.newRequest()
+ String json = ws.newRequest()
.setParam("project", project.getDbKey())
.execute()
.getInput();
- assertJson(json).isSimilarTo(tester.getDef().responseExampleAsString());
+ assertJson(json).isSimilarTo(ws.getDef().responseExampleAsString());
}
}
.executeProtobuf(ShowWsResponse.class);
assertThat(response.getBranch())
- .extracting(Branch::hasName, Branch::getType, Branch::getIsMain, Branch::hasMergeBranch)
- .containsExactlyInAnyOrder(false, Common.BranchType.LONG, true, false);
+ .extracting(Branch::getName, Branch::getType, Branch::getIsMain, Branch::hasMergeBranch)
+ .containsExactlyInAnyOrder("master", Common.BranchType.LONG, true, false);
}
@Test
.executeProtobuf(ShowWsResponse.class);
assertThat(response.getBranch())
- .extracting(Branch::getName, Branch::getType, Branch::getMergeBranch)
- .containsExactlyInAnyOrder(longLivingBranch.getBranch(), Common.BranchType.LONG, "");
+ .extracting(Branch::getName, Branch::getType, Branch::hasMergeBranch)
+ .containsExactlyInAnyOrder(longLivingBranch.getBranch(), Common.BranchType.LONG, false);
}
@Test
.containsExactlyInAnyOrder(shortLivingBranch.getBranch(), Common.BranchType.SHORT, longLivingBranch.getBranch());
}
+ @Test
+ public void mergeBranch_is_using_default_main_name_when_main_branch_has_no_name() {
+ ComponentDto project = db.components().insertMainBranch();
+ userSession.logIn().addProjectPermission(UserRole.USER, project);
+ ComponentDto shortLivingBranch = db.components().insertProjectBranch(project,
+ b -> b.setKey("short").setBranchType(BranchType.SHORT).setMergeBranchUuid(project.uuid()));
+
+ ShowWsResponse response = ws.newRequest()
+ .setParam("component", shortLivingBranch.getKey())
+ .setParam("branch", shortLivingBranch.getBranch())
+ .executeProtobuf(ShowWsResponse.class);
+
+ assertThat(response.getBranch())
+ .extracting(Branch::getName, Branch::getType, Branch::getMergeBranch)
+ .containsExactlyInAnyOrder(shortLivingBranch.getBranch(), Common.BranchType.SHORT, "master");
+ }
+
@Test
public void quality_gate_status_on_long_living_branch() {
ComponentDto project = db.components().insertMainBranch();
.executeProtobuf(ShowWsResponse.class);
assertThat(response.getBranch())
- .extracting(Branch::getName, Branch::getType, Branch::getMergeBranch)
- .containsExactlyInAnyOrder(file.getBranch(), Common.BranchType.LONG, "");
+ .extracting(Branch::getName, Branch::getType, Branch::hasMergeBranch)
+ .containsExactlyInAnyOrder(file.getBranch(), Common.BranchType.LONG, false);
}
@Test