LOCAL_BROWSER(Category.LOCAL, true, true),
ALM_IMPORT_API(Category.ALM_IMPORT, false, false),
ALM_IMPORT_BROWSER(Category.ALM_IMPORT, true, false),
+ ALM_IMPORT_MONOREPO_API(Category.ALM_IMPORT_MONOREPO, false, false),
+ ALM_IMPORT_MONOREPO_BROWSER(Category.ALM_IMPORT_MONOREPO, true, false),
SCANNER_API(Category.SCANNER, false, true),
SCANNER_API_DEVOPS_AUTO_CONFIG(Category.SCANNER, false, false);
return isLocal;
}
- public enum Category {UNKNOWN, LOCAL, ALM_IMPORT, SCANNER}
+ public enum Category {
+ UNKNOWN, LOCAL, ALM_IMPORT, ALM_IMPORT_MONOREPO, SCANNER
+ }
}
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
+import org.sonar.db.project.CreationMethod.Category;
import static org.assertj.core.api.Assertions.assertThat;
static class CreationMethodProvider implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
- return Stream.of(Arguments.of(CreationMethod.Category.UNKNOWN, true, CreationMethod.UNKNOWN),
- Arguments.of(CreationMethod.Category.UNKNOWN, false, CreationMethod.UNKNOWN),
- Arguments.of(CreationMethod.Category.LOCAL, true, CreationMethod.LOCAL_BROWSER),
- Arguments.of(CreationMethod.Category.LOCAL, false, CreationMethod.LOCAL_API),
- Arguments.of(CreationMethod.Category.ALM_IMPORT, true, CreationMethod.ALM_IMPORT_BROWSER),
- Arguments.of(CreationMethod.Category.ALM_IMPORT, false, CreationMethod.ALM_IMPORT_API),
- Arguments.of(CreationMethod.Category.SCANNER, true, CreationMethod.UNKNOWN),
- Arguments.of(CreationMethod.Category.SCANNER, false, CreationMethod.SCANNER_API));
+ return Stream.of(Arguments.of(Category.UNKNOWN, true, CreationMethod.UNKNOWN),
+ Arguments.of(Category.UNKNOWN, false, CreationMethod.UNKNOWN),
+ Arguments.of(Category.LOCAL, true, CreationMethod.LOCAL_BROWSER),
+ Arguments.of(Category.LOCAL, false, CreationMethod.LOCAL_API),
+ Arguments.of(Category.ALM_IMPORT, true, CreationMethod.ALM_IMPORT_BROWSER),
+ Arguments.of(Category.ALM_IMPORT, false, CreationMethod.ALM_IMPORT_API),
+ Arguments.of(Category.ALM_IMPORT_MONOREPO, true, CreationMethod.ALM_IMPORT_MONOREPO_BROWSER),
+ Arguments.of(Category.ALM_IMPORT_MONOREPO, false, CreationMethod.ALM_IMPORT_MONOREPO_API),
+ Arguments.of(Category.SCANNER, true, CreationMethod.UNKNOWN),
+ Arguments.of(Category.SCANNER, false, CreationMethod.SCANNER_API));
}
}
@ParameterizedTest()
@ArgumentsSource(CreationMethodProvider.class)
- void getCreationMethod_returnsCorrectCreationMethod(CreationMethod.Category category, boolean isCreatedViaBrowser,
+ void getCreationMethod_returnsCorrectCreationMethod(Category category, boolean isCreatedViaBrowser,
CreationMethod expectedCreationMethod) {
CreationMethod creationMethod = CreationMethod.getCreationMethod(category, isCreatedViaBrowser);
assertThat(creationMethod).isEqualTo(expectedCreationMethod);
import org.sonar.server.user.UserSession;
import static java.lang.String.format;
-import static org.sonar.db.project.CreationMethod.getCreationMethod;
import static org.sonar.db.project.CreationMethod.Category.ALM_IMPORT;
+import static org.sonar.db.project.CreationMethod.Category.ALM_IMPORT_MONOREPO;
import static org.sonar.server.common.newcodeperiod.NewCodeDefinitionResolver.checkNewCodeDefinitionParam;
@ServerSide
DevOpsProjectCreator projectCreator = devOpsProjectCreatorFactory.getDevOpsProjectCreator(almSetting, projectDescriptor)
.orElseThrow(() -> new IllegalArgumentException(format("Platform %s not supported", almSetting.getAlm().name())));
- CreationMethod creationMethod = getCreationMethod(ALM_IMPORT, userSession.isAuthenticatedBrowserSession());
+ CreationMethod creationMethod = getCreationMethod(request.monorepo());
ComponentCreationData componentCreationData = projectCreator.createProjectAndBindToDevOpsPlatform(
dbSession,
creationMethod,
}
}
+ private CreationMethod getCreationMethod(boolean monorepo) {
+ if (monorepo) {
+ return CreationMethod.getCreationMethod(ALM_IMPORT_MONOREPO, userSession.isAuthenticatedBrowserSession());
+ } else {
+ return CreationMethod.getCreationMethod(ALM_IMPORT, userSession.isAuthenticatedBrowserSession());
+ }
+ }
+
}
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.CreationMethod;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.common.almsettings.DevOpsProjectCreator;
import org.sonar.server.common.almsettings.DevOpsProjectCreatorFactory;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
+import static org.sonar.db.project.CreationMethod.ALM_IMPORT_API;
+import static org.sonar.db.project.CreationMethod.ALM_IMPORT_MONOREPO_API;
class ImportProjectServiceTest {
DevOpsProjectCreator devOpsProjectCreator = mockDevOpsProjectCreator(almSetting);
- ComponentCreationData componentCreationData = mockProjectCreation(devOpsProjectCreator, dbSession);
+ ComponentCreationData componentCreationData = mockProjectCreation(devOpsProjectCreator, ALM_IMPORT_MONOREPO_API, true, dbSession);
ProjectDto projectDto = mockProjectDto(componentCreationData);
when(componentCreationData.mainBranchDto()).thenReturn(mock(BranchDto.class));
DevOpsProjectCreator devOpsProjectCreator = mockDevOpsProjectCreator(almSetting);
- ComponentCreationData componentCreationData = mockProjectCreation(devOpsProjectCreator, dbSession);
+ ComponentCreationData componentCreationData = mockProjectCreation(devOpsProjectCreator, ALM_IMPORT_API, false, dbSession);
ProjectDto projectDto = mockProjectDto(componentCreationData);
mockBranchDto(componentCreationData);
ProjectAlmSettingDto projectAlmSettingDto = mockProjectAlmSetting(dbSession, projectDto);
- ImportProjectRequest request = new ImportProjectRequest(PROJECT_KEY, PROJECT_NAME, ALM_SETTING_ID, DOP_REPOSITORY_ID, DOP_PROJECT_ID, "NUMBER_OF_DAYS", "10", true);
+ ImportProjectRequest request = new ImportProjectRequest(PROJECT_KEY, PROJECT_NAME, ALM_SETTING_ID, DOP_REPOSITORY_ID, DOP_PROJECT_ID, "NUMBER_OF_DAYS", "10", false);
ImportedProject importedProject = importProjectService.importProject(request);
return devOpsProjectCreator;
}
- private static ComponentCreationData mockProjectCreation(DevOpsProjectCreator devOpsProjectCreator, DbSession dbSession) {
+ private static ComponentCreationData mockProjectCreation(DevOpsProjectCreator devOpsProjectCreator, CreationMethod creationMethod, boolean monorepo, DbSession dbSession) {
ComponentCreationData componentCreationData = mock(ComponentCreationData.class);
- when(devOpsProjectCreator.createProjectAndBindToDevOpsPlatform(eq(dbSession), any(), eq(true), eq(PROJECT_KEY), eq(PROJECT_NAME)))
+ when(devOpsProjectCreator.createProjectAndBindToDevOpsPlatform(dbSession, creationMethod, monorepo, PROJECT_KEY, PROJECT_NAME))
.thenReturn(componentCreationData);
return componentCreationData;
}