aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-common
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-webserver-common')
-rw-r--r--server/sonar-webserver-common/src/main/java/org/sonar/server/common/project/ImportProjectService.java12
-rw-r--r--server/sonar-webserver-common/src/test/java/org/sonar/server/common/project/ImportProjectServiceTest.java13
2 files changed, 18 insertions, 7 deletions
diff --git a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/project/ImportProjectService.java b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/project/ImportProjectService.java
index e2b8f841f12..ef714ed876f 100644
--- a/server/sonar-webserver-common/src/main/java/org/sonar/server/common/project/ImportProjectService.java
+++ b/server/sonar-webserver-common/src/main/java/org/sonar/server/common/project/ImportProjectService.java
@@ -37,8 +37,8 @@ import org.sonar.server.component.ComponentCreationData;
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
@@ -68,7 +68,7 @@ public class ImportProjectService {
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,
@@ -91,4 +91,12 @@ public class ImportProjectService {
}
}
+ private CreationMethod getCreationMethod(boolean monorepo) {
+ if (monorepo) {
+ return CreationMethod.getCreationMethod(ALM_IMPORT_MONOREPO, userSession.isAuthenticatedBrowserSession());
+ } else {
+ return CreationMethod.getCreationMethod(ALM_IMPORT, userSession.isAuthenticatedBrowserSession());
+ }
+ }
+
}
diff --git a/server/sonar-webserver-common/src/test/java/org/sonar/server/common/project/ImportProjectServiceTest.java b/server/sonar-webserver-common/src/test/java/org/sonar/server/common/project/ImportProjectServiceTest.java
index 4bf728aee16..7ef4c197df9 100644
--- a/server/sonar-webserver-common/src/test/java/org/sonar/server/common/project/ImportProjectServiceTest.java
+++ b/server/sonar-webserver-common/src/test/java/org/sonar/server/common/project/ImportProjectServiceTest.java
@@ -29,6 +29,7 @@ import org.sonar.db.alm.setting.ALM;
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;
@@ -47,6 +48,8 @@ import static org.mockito.Mockito.mock;
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 {
@@ -111,7 +114,7 @@ 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));
@@ -136,14 +139,14 @@ class ImportProjectServiceTest {
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);
@@ -182,9 +185,9 @@ class ImportProjectServiceTest {
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;
}