return project;
}
+ @SafeVarargs
+ public final ComponentDto insertMainBranch(OrganizationDto organization, String mainBranchName, Consumer<ComponentDto>... dtoPopulators) {
+ ComponentDto project = newPrivateProjectDto(organization);
+ BranchDto branchDto = newBranchDto(project, LONG).setKey(mainBranchName);
+ Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(project));
+ insertComponent(project);
+ dbClient.branchDao().insert(dbSession, branchDto);
+ db.commit();
+ return project;
+ }
+
@SafeVarargs
public final ComponentDto insertProjectBranch(ComponentDto project, Consumer<BranchDto>... dtoPopulators) {
// MainBranchProjectUuid will be null if it's a main branch
action
.createParam(PARAM_BRANCH)
.setDescription("Branch key")
- .setExampleValue(KEY_BRANCH_EXAMPLE_001)
- .setRequired(true);
+ .setExampleValue(KEY_BRANCH_EXAMPLE_001);
}
@Override
public void handle(Request request, Response response) throws Exception {
String projectKey = request.mandatoryParam(PARAM_COMPONENT);
- String branchName = request.mandatoryParam(PARAM_BRANCH);
+ String branchName = request.param(PARAM_BRANCH);
try (DbSession dbSession = dbClient.openSession(false)) {
- ComponentDto component = componentFinder.getByKeyAndBranch(dbSession, projectKey, branchName);
+ ComponentDto component = loadComponent(dbSession, projectKey, branchName);
userSession.checkComponentPermission(UserRole.USER, component);
List<MetricDto> metrics = dbClient.metricDao().selectByKeys(dbSession, asList(ALERT_STATUS_KEY, BUGS_KEY, VULNERABILITIES_KEY, CODE_SMELLS_KEY));
}
}
+ private ComponentDto loadComponent(DbSession dbSession, String projectKey, @Nullable String branchName){
+ if (branchName == null) {
+ return componentFinder.getByKey(dbSession, projectKey);
+ }
+ return componentFinder.getByKeyAndBranch(dbSession, projectKey, branchName);
+ }
+
private BranchDto getBranch(DbSession dbSession, String uuid) {
Optional<BranchDto> branch = dbClient.branchDao().selectByUuid(dbSession, uuid);
checkState(branch.isPresent(), "Branch uuid '%s' not found", uuid);
assertThat(definition.since()).isEqualTo("6.6");
}
+ @Test
+ public void main_branch_when_no_branch_parameter() {
+ ComponentDto project = db.components().insertMainBranch();
+ userSession.logIn().addProjectPermission(UserRole.USER, project);
+
+ ShowWsResponse response = ws.newRequest()
+ .setParam("component", project.getKey())
+ .executeProtobuf(ShowWsResponse.class);
+
+ assertThat(response.getBranch())
+ .extracting(Branch::hasName, Branch::getType, Branch::getIsMain, Branch::hasMergeBranch)
+ .containsExactlyInAnyOrder(false, Common.BranchType.LONG, true, false);
+ }
+
+ @Test
+ public void main_branch_with_name() {
+ OrganizationDto organizationD = db.organizations().insert();
+ ComponentDto project = db.components().insertMainBranch(organizationD, "head");
+
+ userSession.logIn().addProjectPermission(UserRole.USER, project);
+
+ ShowWsResponse response = ws.newRequest()
+ .setParam("component", project.getKey())
+ .executeProtobuf(ShowWsResponse.class);
+
+ assertThat(response.getBranch())
+ .extracting(Branch::getName, Branch::getType, Branch::getIsMain)
+ .containsExactlyInAnyOrder("head", Common.BranchType.LONG, true);
+ }
+
@Test
public void long_living_branch() {
ComponentDto project = db.components().insertMainBranch();
.setParam("branch", shortLivingBranch.getBranch())
.executeProtobuf(ShowWsResponse.class);
-
assertThat(response.getBranch().getStatus())
- .extracting(Branch.Status::hasBugs, Branch.Status::getBugs, Branch.Status::hasVulnerabilities, Branch.Status::getVulnerabilities, Branch.Status::hasCodeSmells, Branch.Status::getCodeSmells)
+ .extracting(Branch.Status::hasBugs, Branch.Status::getBugs, Branch.Status::hasVulnerabilities, Branch.Status::getVulnerabilities, Branch.Status::hasCodeSmells,
+ Branch.Status::getCodeSmells)
.containsExactlyInAnyOrder(true, 1, true, 2, true, 3);
}
.execute();
}
- @Test
- public void fail_if_missing_branch_parameter() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("The 'branch' parameter is missing");
-
- ws.newRequest()
- .setParam("component", "my_project")
- .execute();
- }
-
@Test
public void fail_if_branch_does_not_exist() {
ComponentDto project = db.components().insertPrivateProject();