diff options
author | Wojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com> | 2024-03-27 14:54:08 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-03-28 20:02:50 +0000 |
commit | 0720dee972bcc286fad8f8b73000dfe07aaca5b3 (patch) | |
tree | 4037b1d83b6a9c0a9d727a9b2c7844e080c59835 /server/sonar-webserver-common | |
parent | 50f49a4d7a17aecc35290234dc9bdca638b21cd6 (diff) | |
download | sonarqube-0720dee972bcc286fad8f8b73000dfe07aaca5b3.tar.gz sonarqube-0720dee972bcc286fad8f8b73000dfe07aaca5b3.zip |
SONAR-21821 Add monorepo related project 'CreationMethod's
Diffstat (limited to 'server/sonar-webserver-common')
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; } |