Projects.CreateWsResponse.Project result = response.getProject();
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
+ BranchDto branchDto = db.getDbClient().branchDao().selectMainBranchByProjectUuid(db.getSession(), projectDto.get().getUuid()).orElseThrow();
assertThat(projectDto).isPresent();
String projectUuid = projectDto.get().getUuid();
- assertThat(db.getDbClient().newCodePeriodDao().selectByBranch(db.getSession(), projectUuid, projectUuid))
+ assertThat(db.getDbClient().newCodePeriodDao().selectByBranch(db.getSession(), projectUuid, branchDto.getUuid()))
.isPresent()
.get()
.extracting(NewCodePeriodDto::getType, NewCodePeriodDto::getValue, NewCodePeriodDto::getBranchUuid)
- .containsExactly(NUMBER_OF_DAYS, "30", projectUuid);
+ .containsExactly(NUMBER_OF_DAYS, "30", branchDto.getUuid());
}
@Test
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
assertThat(projectDto).isPresent();
+ BranchDto branchDto = db.getDbClient().branchDao().selectMainBranchByProjectUuid(db.getSession(), projectDto.get().getUuid()).orElseThrow();
String projectUuid = projectDto.get().getUuid();
- assertThat(db.getDbClient().newCodePeriodDao().selectByBranch(db.getSession(), projectUuid, projectUuid))
+ assertThat(db.getDbClient().newCodePeriodDao().selectByBranch(db.getSession(), projectUuid, branchDto.getUuid()))
.isPresent()
.get()
.extracting(NewCodePeriodDto::getType, NewCodePeriodDto::getValue, NewCodePeriodDto::getBranchUuid)
- .containsExactly(NUMBER_OF_DAYS, "30", projectUuid);
+ .containsExactly(NUMBER_OF_DAYS, "30", branchDto.getUuid());
}
@Test
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
assertThat(projectDto).isPresent();
+ BranchDto branchDto = db.getDbClient().branchDao().selectMainBranchByProjectUuid(db.getSession(), projectDto.get().getUuid()).orElseThrow();
String projectUuid = projectDto.get().getUuid();
- assertThat(db.getDbClient().newCodePeriodDao().selectByBranch(db.getSession(), projectUuid, projectUuid))
+ assertThat(db.getDbClient().newCodePeriodDao().selectByBranch(db.getSession(), projectUuid, branchDto.getUuid()))
.isPresent()
.get()
.extracting(NewCodePeriodDto::getType, NewCodePeriodDto::getValue, NewCodePeriodDto::getBranchUuid)
- .containsExactly(NUMBER_OF_DAYS, "30", projectUuid);
+ .containsExactly(NUMBER_OF_DAYS, "30", branchDto.getUuid());
}
@Test
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
assertThat(projectDto).isPresent();
-
String projectUuid = projectDto.get().getUuid();
assertThat(db.getDbClient().newCodePeriodDao().selectByProject(db.getSession(), projectUuid))
.isPresent()
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
assertThat(projectDto).isPresent();
+ BranchDto branchDto = db.getDbClient().branchDao().selectMainBranchByProjectUuid(db.getSession(), projectDto.get().getUuid()).orElseThrow();
String projectUuid = projectDto.get().getUuid();
- assertThat(db.getDbClient().newCodePeriodDao().selectByBranch(db.getSession(), projectUuid, projectUuid))
+ assertThat(db.getDbClient().newCodePeriodDao().selectByBranch(db.getSession(), projectUuid, branchDto.getUuid()))
.isPresent()
.get()
.extracting(NewCodePeriodDto::getType, NewCodePeriodDto::getValue, NewCodePeriodDto::getBranchUuid)
- .containsExactly(NUMBER_OF_DAYS, "30", projectUuid);
+ .containsExactly(NUMBER_OF_DAYS, "30", branchDto.getUuid());
}
@Test
Projects.CreateWsResponse.Project result = response.getProject();
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
+ BranchDto branchDto = db.getDbClient().branchDao().selectMainBranchByProjectUuid(db.getSession(), projectDto.get().getUuid()).orElseThrow();
String projectUuid = projectDto.get().getUuid();
- assertThat(db.getDbClient().newCodePeriodDao().selectByBranch(db.getSession(), projectUuid, projectUuid))
+ assertThat(db.getDbClient().newCodePeriodDao().selectByBranch(db.getSession(), projectUuid, branchDto.getUuid()))
.isPresent()
.get()
.extracting(NewCodePeriodDto::getType, NewCodePeriodDto::getValue, NewCodePeriodDto::getBranchUuid)
- .containsExactly(NUMBER_OF_DAYS, "30", projectUuid);
+ .containsExactly(NUMBER_OF_DAYS, "30", branchDto.getUuid());
}
@Test
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.newcodeperiod.NewCodePeriodDto;
+import org.sonar.server.component.ComponentCreationData;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;
public class NewCodeDefinitionResolverTest {
+ private static final String MAIN_BRANCH_UUID = "main-branch-uuid";
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
@Test
public void createNewCodeDefinition_throw_IAE_if_no_valid_type() {
- assertThatThrownBy(() -> newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH, "nonValid", null))
+ assertThatThrownBy(() -> newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH_UUID, MAIN_BRANCH, "nonValid", null))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Invalid type: nonValid");
}
@Test
public void createNewCodeDefinition_throw_IAE_if_type_is_not_allowed() {
- assertThatThrownBy(() -> newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH, SPECIFIC_ANALYSIS.name(), null))
+ assertThatThrownBy(() -> newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH_UUID, MAIN_BRANCH, SPECIFIC_ANALYSIS.name(), null))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Invalid type 'SPECIFIC_ANALYSIS'. `newCodeDefinitionType` can only be set with types: [PREVIOUS_VERSION, NUMBER_OF_DAYS, REFERENCE_BRANCH]");
}
@Test
public void createNewCodeDefinition_throw_IAE_if_no_value_for_days() {
- assertThatThrownBy(() -> newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH, NUMBER_OF_DAYS.name(), null))
+ assertThatThrownBy(() -> newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH_UUID, MAIN_BRANCH, NUMBER_OF_DAYS.name(), null))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("New code definition type 'NUMBER_OF_DAYS' requires a newCodeDefinitionValue");
}
@Test
public void createNewCodeDefinition_throw_IAE_if_days_is_invalid() {
- assertThatThrownBy(() -> newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH, NUMBER_OF_DAYS.name(), "unknown"))
+ assertThatThrownBy(() -> newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH_UUID, MAIN_BRANCH, NUMBER_OF_DAYS.name(), "unknown"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Failed to parse number of days: unknown");
}
@Test
public void createNewCodeDefinition_throw_IAE_if_value_is_set_for_reference_branch() {
- assertThatThrownBy(() -> newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH, REFERENCE_BRANCH.name(), "feature/zw"))
+ assertThatThrownBy(() -> newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH_UUID, MAIN_BRANCH, REFERENCE_BRANCH.name(), "feature/zw"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Unexpected value for newCodeDefinitionType 'REFERENCE_BRANCH'");
}
@Test
public void createNewCodeDefinition_throw_IAE_if_previous_version_type_and_value_provided() {
- assertThatThrownBy(() -> newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH, PREVIOUS_VERSION.name(), "10.2.3"))
+ assertThatThrownBy(() -> newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH_UUID, MAIN_BRANCH, PREVIOUS_VERSION.name(), "10.2.3"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Unexpected value for newCodeDefinitionType 'PREVIOUS_VERSION'");
}
@Test
public void createNewCodeDefinition_persist_previous_version_type() {
- newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH, PREVIOUS_VERSION.name(), null);
+ newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH_UUID, MAIN_BRANCH, PREVIOUS_VERSION.name(), null);
Optional<NewCodePeriodDto> newCodePeriodDto = dbClient.newCodePeriodDao().selectByProject(dbSession, DEFAULT_PROJECT_ID);
assertThat(newCodePeriodDto).map(NewCodePeriodDto::getType).hasValue(PREVIOUS_VERSION);
public void createNewCodeDefinition_return_days_value_for_number_of_days_type() {
String numberOfDays = "30";
- newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH, NUMBER_OF_DAYS.name(), numberOfDays);
+ newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH_UUID, MAIN_BRANCH, NUMBER_OF_DAYS.name(), numberOfDays);
Optional<NewCodePeriodDto> newCodePeriodDto = dbClient.newCodePeriodDao().selectByProject(dbSession, DEFAULT_PROJECT_ID);
@Test
public void createNewCodeDefinition_return_branch_value_for_reference_branch_type() {
- newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH, REFERENCE_BRANCH.name(), null);
+ newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH_UUID, MAIN_BRANCH, REFERENCE_BRANCH.name(), null);
Optional<NewCodePeriodDto> newCodePeriodDto = dbClient.newCodePeriodDao().selectByProject(dbSession, DEFAULT_PROJECT_ID);
assertThat(newCodePeriodDto)
.isPresent()
.get()
- .extracting(NewCodePeriodDto::getType, NewCodePeriodDto::getValue)
- .containsExactly(REFERENCE_BRANCH, MAIN_BRANCH);
+ .extracting(NewCodePeriodDto::getType, NewCodePeriodDto::getValue, NewCodePeriodDto::getBranchUuid, NewCodePeriodDto::getProjectUuid)
+ .containsExactly(REFERENCE_BRANCH, MAIN_BRANCH, null, DEFAULT_PROJECT_ID);
}
@Test
.setNewCodeDefinitionType(REFERENCE_BRANCH.name())
.build());
- ComponentDto component = db.getDbClient().componentDao().selectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get();
+ ProjectDto projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get();
- assertThat(db.getDbClient().newCodePeriodDao().selectByProject(db.getSession(), component.uuid()))
+ assertThat(db.getDbClient().newCodePeriodDao().selectByProject(db.getSession(), projectDto.getUuid()))
.isPresent()
.get()
.extracting(NewCodePeriodDto::getType, NewCodePeriodDto::getValue)
.setNewCodeDefinitionType(REFERENCE_BRANCH.name())
.build());
- ComponentDto component = db.getDbClient().componentDao().selectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get();
+ ProjectDto projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get();
- assertThat(db.getDbClient().newCodePeriodDao().selectByProject(db.getSession(), component.uuid()))
+ assertThat(db.getDbClient().newCodePeriodDao().selectByProject(db.getSession(), projectDto.getUuid()))
.isPresent()
.get()
.extracting(NewCodePeriodDto::getType, NewCodePeriodDto::getValue)
.setNewCodeDefinitionValue("30")
.build());
- ComponentDto component = db.getDbClient().componentDao().selectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get();
+ ProjectDto projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get();
- assertThat(db.getDbClient().newCodePeriodDao().selectByProject(db.getSession(), component.uuid()))
+ assertThat(db.getDbClient().newCodePeriodDao().selectByProject(db.getSession(), projectDto.getUuid()))
.isPresent()
.get()
.extracting(NewCodePeriodDto::getType, NewCodePeriodDto::getValue)
.setNewCodeDefinitionValue("30")
.build());
+ ProjectDto projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get();
ComponentDto component = db.getDbClient().componentDao().selectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get();
- assertThat(db.getDbClient().newCodePeriodDao().selectByBranch(db.getSession(), component.uuid(), component.uuid()))
+ assertThat(db.getDbClient().newCodePeriodDao().selectByBranch(db.getSession(), projectDto.getUuid(), component.uuid()))
.isPresent()
.get()
.extracting(NewCodePeriodDto::getType, NewCodePeriodDto::getValue, NewCodePeriodDto::getBranchUuid)
.setNewCodeDefinitionValue("30")
.build());
- ComponentDto component = db.getDbClient().componentDao().selectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get();
+ ProjectDto projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get();
- assertThat(db.getDbClient().newCodePeriodDao().selectByProject(db.getSession(), component.uuid()))
+ assertThat(db.getDbClient().newCodePeriodDao().selectByProject(db.getSession(), projectDto.getUuid()))
.isPresent()
.get()
.extracting(NewCodePeriodDto::getType, NewCodePeriodDto::getValue, NewCodePeriodDto::getBranchUuid)
import org.sonar.db.alm.pat.AlmPatDto;
import org.sonar.db.alm.setting.AlmSettingDto;
import org.sonar.db.alm.setting.ProjectAlmSettingDto;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.almintegration.ws.AlmIntegrationsWsAction;
import org.sonar.server.almintegration.ws.ImportHelper;
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction("import_azure_project")
.setDescription("Create a SonarQube project with the information from the provided Azure DevOps project.<br/>" +
- "Autoconfigure pull request decoration mechanism.<br/>" +
- "Requires the 'Create Projects' permission")
+ "Autoconfigure pull request decoration mechanism.<br/>" +
+ "Requires the 'Create Projects' permission")
.setPost(true)
.setInternal(true)
.setSince("8.6")
ComponentCreationData componentCreationData = createProject(dbSession, repo);
ProjectDto projectDto = Optional.ofNullable(componentCreationData.projectDto()).orElseThrow();
+ BranchDto mainBranchDto = Optional.ofNullable(componentCreationData.mainBranchDto()).orElseThrow();
populatePRSetting(dbSession, repo, projectDto, almSettingDto);
checkNewCodeDefinitionParam(newCodeDefinitionType, newCodeDefinitionValue);
if (newCodeDefinitionType != null) {
- newCodeDefinitionResolver.createNewCodeDefinition(dbSession, projectDto.getUuid(),
+ newCodeDefinitionResolver.createNewCodeDefinition(dbSession, projectDto.getUuid(), mainBranchDto.getUuid(),
Optional.ofNullable(repo.getDefaultBranchName()).orElse(defaultBranchNameResolver.getEffectiveMainBranchName()),
newCodeDefinitionType, newCodeDefinitionValue);
}
import org.sonar.db.alm.pat.AlmPatDto;
import org.sonar.db.alm.setting.AlmSettingDto;
import org.sonar.db.alm.setting.ProjectAlmSettingDto;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.almintegration.ws.AlmIntegrationsWsAction;
import org.sonar.server.almintegration.ws.ImportHelper;
ComponentCreationData componentCreationData = createProject(dbSession, workspace, repo, repo.getMainBranch().getName());
ProjectDto projectDto = Optional.ofNullable(componentCreationData.projectDto()).orElseThrow();
+ BranchDto mainBranchDto = Optional.ofNullable(componentCreationData.mainBranchDto()).orElseThrow();
populatePRSetting(dbSession, repo, projectDto, almSettingDto);
checkNewCodeDefinitionParam(newCodeDefinitionType, newCodeDefinitionValue);
if (newCodeDefinitionType != null) {
- newCodeDefinitionResolver.createNewCodeDefinition(dbSession, projectDto.getUuid(),
+ newCodeDefinitionResolver.createNewCodeDefinition(dbSession, projectDto.getUuid(), mainBranchDto.getUuid(),
Optional.ofNullable(repo.getMainBranch().getName()).orElse(defaultBranchNameResolver.getEffectiveMainBranchName()),
newCodeDefinitionType, newCodeDefinitionValue);
}
import org.sonar.db.alm.pat.AlmPatDto;
import org.sonar.db.alm.setting.AlmSettingDto;
import org.sonar.db.alm.setting.ProjectAlmSettingDto;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.almintegration.ws.AlmIntegrationsWsAction;
import org.sonar.server.almintegration.ws.ImportHelper;
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction("import_bitbucketserver_project")
.setDescription("Create a SonarQube project with the information from the provided BitbucketServer project.<br/>" +
- "Autoconfigure pull request decoration mechanism.<br/>" +
- "Requires the 'Create Projects' permission")
+ "Autoconfigure pull request decoration mechanism.<br/>" +
+ "Requires the 'Create Projects' permission")
.setPost(true)
.setInternal(true)
.setSince("8.2")
ComponentCreationData componentCreationData = createProject(dbSession, repo, defaultBranchName);
ProjectDto projectDto = Optional.ofNullable(componentCreationData.projectDto()).orElseThrow();
+ BranchDto mainBranchDto = Optional.ofNullable(componentCreationData.mainBranchDto()).orElseThrow();
populatePRSetting(dbSession, repo, projectDto, almSettingDto);
checkNewCodeDefinitionParam(newCodeDefinitionType, newCodeDefinitionValue);
if (newCodeDefinitionType != null) {
- newCodeDefinitionResolver.createNewCodeDefinition(dbSession, projectDto.getUuid(),
+ newCodeDefinitionResolver.createNewCodeDefinition(dbSession, projectDto.getUuid(), mainBranchDto.getUuid(),
Optional.ofNullable(defaultBranchName).orElse(defaultBranchNameResolver.getEffectiveMainBranchName()),
newCodeDefinitionType, newCodeDefinitionValue);
}
import org.sonar.db.alm.pat.AlmPatDto;
import org.sonar.db.alm.setting.AlmSettingDto;
import org.sonar.db.alm.setting.ProjectAlmSettingDto;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.almintegration.ws.AlmIntegrationsWsAction;
import org.sonar.server.almintegration.ws.ImportHelper;
ComponentCreationData componentCreationData = createProject(dbSession, repository, repository.getDefaultBranch());
ProjectDto projectDto = Optional.ofNullable(componentCreationData.projectDto()).orElseThrow();
+ BranchDto mainBranchDto = Optional.ofNullable(componentCreationData.mainBranchDto()).orElseThrow();
populatePRSetting(dbSession, repository, projectDto, almSettingDto);
checkNewCodeDefinitionParam(newCodeDefinitionType, newCodeDefinitionValue);
if (newCodeDefinitionType != null) {
- newCodeDefinitionResolver.createNewCodeDefinition(dbSession, projectDto.getUuid(),
+ newCodeDefinitionResolver.createNewCodeDefinition(dbSession, projectDto.getUuid(), mainBranchDto.getUuid(),
Optional.ofNullable(repository.getDefaultBranch()).orElse(defaultBranchNameResolver.getEffectiveMainBranchName()),
newCodeDefinitionType, newCodeDefinitionValue);
}
import org.sonar.db.alm.pat.AlmPatDto;
import org.sonar.db.alm.setting.AlmSettingDto;
import org.sonar.db.alm.setting.ProjectAlmSettingDto;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.almintegration.ws.AlmIntegrationsWsAction;
import org.sonar.server.almintegration.ws.ImportHelper;
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction("import_gitlab_project")
.setDescription("Import a GitLab project to SonarQube, creating a new project and configuring MR decoration<br/>" +
- "Requires the 'Create Projects' permission")
+ "Requires the 'Create Projects' permission")
.setPost(true)
.setSince("8.5")
.setHandler(this);
ComponentCreationData componentCreationData = createProject(dbSession, gitlabProject, almMainBranchName.orElse(null));
ProjectDto projectDto = Optional.ofNullable(componentCreationData.projectDto()).orElseThrow();
+ BranchDto mainBranchDto = Optional.ofNullable(componentCreationData.mainBranchDto()).orElseThrow();
populateMRSetting(dbSession, gitlabProjectId, projectDto, almSettingDto);
checkNewCodeDefinitionParam(newCodeDefinitionType, newCodeDefinitionValue);
if (newCodeDefinitionType != null) {
- newCodeDefinitionResolver.createNewCodeDefinition(dbSession, projectDto.getUuid(), almMainBranchName.orElse(defaultBranchNameResolver.getEffectiveMainBranchName()),
- newCodeDefinitionType, newCodeDefinitionValue);
+ newCodeDefinitionResolver.createNewCodeDefinition(dbSession, projectDto.getUuid(), mainBranchDto.getUuid(),
+ almMainBranchName.orElse(defaultBranchNameResolver.getEffectiveMainBranchName()), newCodeDefinitionType, newCodeDefinitionValue);
}
componentUpdater.commitAndIndex(dbSession, componentCreationData);
import org.sonar.db.newcodeperiod.NewCodePeriodDto;
import org.sonar.db.newcodeperiod.NewCodePeriodParser;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
+import org.sonar.server.component.ComponentCreationData;
import static org.sonar.db.newcodeperiod.NewCodePeriodType.NUMBER_OF_DAYS;
import static org.sonar.db.newcodeperiod.NewCodePeriodType.PREVIOUS_VERSION;
this.editionProvider = editionProvider;
}
- public void createNewCodeDefinition(DbSession dbSession, String projectUuid, String defaultBranchName, String newCodeDefinitionType, String newCodeDefinitionValue) {
+ public void createNewCodeDefinition(DbSession dbSession, String projectUuid, String mainBranchUuid,
+ String defaultBranchName, String newCodeDefinitionType, String newCodeDefinitionValue) {
boolean isCommunityEdition = editionProvider.get().filter(EditionProvider.Edition.COMMUNITY::equals).isPresent();
NewCodePeriodType newCodePeriodType = parseNewCodeDefinitionType(newCodeDefinitionType);
dto.setProjectUuid(projectUuid);
if (isCommunityEdition) {
- dto.setBranchUuid(projectUuid);
+ dto.setBranchUuid(mainBranchUuid);
}
getNewCodeDefinitionValueProjectCreation(newCodePeriodType, newCodeDefinitionValue, defaultBranchName).ifPresent(dto::setValue);
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.entity.EntityDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentCreationData;
import org.sonar.server.component.ComponentUpdater;
import org.sonar.server.newcodeperiod.NewCodeDefinitionResolver;
userSession.checkPermission(PROVISION_PROJECTS);
checkNewCodeDefinitionParam(request.getNewCodeDefinitionType(), request.getNewCodeDefinitionValue());
ComponentCreationData componentData = createProject(request, dbSession);
+ ProjectDto projectDto = Optional.ofNullable(componentData.projectDto()).orElseThrow();
+ BranchDto mainBranchDto = Optional.ofNullable(componentData.mainBranchDto()).orElseThrow();
+
if (request.getNewCodeDefinitionType() != null) {
String defaultBranchName = Optional.ofNullable(request.getMainBranchKey()).orElse(defaultBranchNameResolver.getEffectiveMainBranchName());
- newCodeDefinitionResolver.createNewCodeDefinition(dbSession, componentData.mainBranchDto().getUuid(), defaultBranchName, request.getNewCodeDefinitionType(),
+ newCodeDefinitionResolver.createNewCodeDefinition(dbSession, projectDto.getUuid(),
+ mainBranchDto.getUuid(), defaultBranchName, request.getNewCodeDefinitionType(),
request.getNewCodeDefinitionValue());
}
componentUpdater.commitAndIndex(dbSession, componentData);
- return toCreateResponse(componentData.projectDto());
+ return toCreateResponse(projectDto);
}
}