From: Philippe Perrin Date: Fri, 9 Jun 2023 15:40:34 +0000 (+0200) Subject: SONAR-19458 New code definition is made part of Azure project onboarding X-Git-Tag: 10.1.0.73491~50 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6139a5a6e75c167a72f14cbb33d02fbe7df6c9e2;p=sonarqube.git SONAR-19458 New code definition is made part of Azure project onboarding --- diff --git a/server/sonar-web/src/main/js/api/alm-integrations.ts b/server/sonar-web/src/main/js/api/alm-integrations.ts index e66a15b098a..451e20fbfb5 100644 --- a/server/sonar-web/src/main/js/api/alm-integrations.ts +++ b/server/sonar-web/src/main/js/api/alm-integrations.ts @@ -80,16 +80,23 @@ export function searchAzureRepositories( ); } -export function importAzureRepository( - almSetting: string, - projectName: string, - repositoryName: string -): Promise<{ project: ProjectBase }> { - return postJSON('/api/alm_integrations/import_azure_project', { - almSetting, - projectName, - repositoryName, - }).catch(throwGlobalError); +export function setupAzureProjectCreation(data: { + almSetting: string; + projectName: string; + repositoryName: string; +}) { + return (newCodeDefinitionType?: string, newCodeDefinitionValue?: string) => + importAzureRepository({ ...data, newCodeDefinitionType, newCodeDefinitionValue }); +} + +export function importAzureRepository(data: { + almSetting: string; + projectName: string; + repositoryName: string; + newCodeDefinitionType?: string; + newCodeDefinitionValue?: string; +}): Promise<{ project: ProjectBase }> { + return postJSON('/api/alm_integrations/import_azure_project', data).catch(throwGlobalError); } export function getBitbucketServerProjects( diff --git a/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts index 48ce63147f5..0a1002c8842 100644 --- a/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts @@ -57,6 +57,7 @@ import { searchForBitbucketCloudRepositories, searchForBitbucketServerRepositories, setAlmPersonalAccessToken, + setupAzureProjectCreation, } from '../alm-integrations'; export default class AlmIntegrationsServiceMock { @@ -192,6 +193,7 @@ export default class AlmIntegrationsServiceMock { jest.mocked(getAzureRepositories).mockImplementation(this.getAzureRepositories); jest.mocked(getGithubRepositories).mockImplementation(this.getGithubRepositories); jest.mocked(searchAzureRepositories).mockImplementation(this.searchAzureRepositories); + jest.mocked(setupAzureProjectCreation).mockReturnValue(() => this.importAzureRepository()); jest.mocked(importAzureRepository).mockImplementation(this.importAzureRepository); jest.mocked(importGithubRepository).mockImplementation(this.importGithubRepository); jest diff --git a/server/sonar-web/src/main/js/apps/create/project/Azure/AzureProjectAccordion.tsx b/server/sonar-web/src/main/js/apps/create/project/Azure/AzureProjectAccordion.tsx index 3556cc7ecbc..8d58b630c2c 100644 --- a/server/sonar-web/src/main/js/apps/create/project/Azure/AzureProjectAccordion.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/Azure/AzureProjectAccordion.tsx @@ -34,7 +34,6 @@ import { AzureProject, AzureRepository } from '../../../../types/alm-integration import { CreateProjectModes } from '../types'; export interface AzureProjectAccordionProps { - importing: boolean; loading: boolean; onOpen: (key: string) => void; onSelectRepository: (repository: AzureRepository) => void; @@ -66,7 +65,6 @@ function highlight(text: string, term?: string, underline = false) { export default function AzureProjectAccordion(props: AzureProjectAccordionProps) { const { - importing, loading, startsOpen, project, @@ -148,7 +146,6 @@ export default function AzureProjectAccordion(props: AzureProjectAccordionProps) checked={isSelected(repo)} className="overflow-hidden" alignLabel - disabled={importing} onCheck={() => props.onSelectRepository(repo)} value={repo.name} > diff --git a/server/sonar-web/src/main/js/apps/create/project/Azure/AzureProjectCreate.tsx b/server/sonar-web/src/main/js/apps/create/project/Azure/AzureProjectCreate.tsx index a65f7c57fe1..ef64815293c 100644 --- a/server/sonar-web/src/main/js/apps/create/project/Azure/AzureProjectCreate.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/Azure/AzureProjectCreate.tsx @@ -22,28 +22,28 @@ import { checkPersonalAccessTokenIsValid, getAzureProjects, getAzureRepositories, - importAzureRepository, searchAzureRepositories, setAlmPersonalAccessToken, + setupAzureProjectCreation, } from '../../../../api/alm-integrations'; import { Location, Router } from '../../../../components/hoc/withRouter'; import { AzureProject, AzureRepository } from '../../../../types/alm-integration'; import { AlmSettingsInstance } from '../../../../types/alm-settings'; import { Dict } from '../../../../types/types'; +import { CreateProjectApiCallback } from '../types'; import { tokenExistedBefore } from '../utils'; import AzureCreateProjectRenderer from './AzureProjectCreateRenderer'; interface Props { canAdmin: boolean; loadingBindings: boolean; - onProjectCreate: (projectKey: string) => void; almInstances: AlmSettingsInstance[]; location: Location; router: Router; + onProjectSetupDone: (createProject: CreateProjectApiCallback) => void; } interface State { - importing: boolean; loading: boolean; loadingRepositories: Dict; patIsValid?: boolean; @@ -65,10 +65,7 @@ export default class AzureProjectCreate extends React.PureComponent { + handleImportRepository = () => { const { selectedRepository, selectedAlmInstance } = this.state; - if (!selectedAlmInstance || !selectedRepository) { - return; - } - - this.setState({ importing: true }); - - const createdProject = await importAzureRepository( - selectedAlmInstance.key, - selectedRepository.projectName, - selectedRepository.name - ) - .then(({ project }) => project) - .catch(() => undefined); - - if (this.mounted) { - this.setState({ importing: false }); - if (createdProject) { - this.props.onProjectCreate(createdProject.key); - } + if (selectedAlmInstance && selectedRepository) { + this.props.onProjectSetupDone( + setupAzureProjectCreation({ + almSetting: selectedAlmInstance.key, + projectName: selectedRepository.projectName, + repositoryName: selectedRepository.name, + }) + ); } }; @@ -301,7 +287,6 @@ export default class AzureProjectCreate extends React.PureComponent; onImportRepository: () => void; @@ -66,7 +64,6 @@ export interface AzureProjectCreateRendererProps { export default function AzureProjectCreateRenderer(props: AzureProjectCreateRendererProps) { const { canAdmin, - importing, loading, loadingRepositories, projects, @@ -94,10 +91,9 @@ export default function AzureProjectCreateRenderer(props: AzureProjectCreateRend !showPersonalAccessTokenForm && settingIsValid && (
-
) : ( <> - -
; onOpenProject: (key: string) => void; onSelectRepository: (repository: AzureRepository) => void; @@ -46,7 +45,6 @@ const PAGE_SIZE = 10; export default function AzureProjectsList(props: AzureProjectsListProps) { const { - importing, loadingRepositories, projects = [], repositories, @@ -119,7 +117,6 @@ export default function AzureProjectsList(props: AzureProjectsListProps) { {displayedProjects.map((p, i) => ( ); } diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/Azure-it.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/Azure-it.tsx index 8ddbbacb833..db729469f48 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/Azure-it.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/Azure-it.tsx @@ -105,6 +105,17 @@ it('should show import project feature when PAT is already set', async () => { expect(importButton).toBeEnabled(); await user.click(importButton); + expect( + screen.getByRole('heading', { name: 'onboarding.create_project.new_code_definition.title' }) + ).toBeInTheDocument(); + + await user.click(screen.getByRole('radio', { name: 'new_code_definition.global_setting' })); + await user.click( + screen.getByRole('button', { + name: 'onboarding.create_project.new_code_definition.create_project', + }) + ); + expect(await screen.findByText('/dashboard?id=key')).toBeInTheDocument(); });