From fb56254f6aedba9c8c63dee5ef73cca636f1ccab Mon Sep 17 00:00:00 2001 From: Philippe Perrin Date: Fri, 9 Jun 2023 11:52:38 +0200 Subject: [PATCH] SONAR-19456 New code definition is made part of Bitbucket Server project onboarding --- .../src/main/js/api/alm-integrations.ts | 29 +++++++++----- .../api/mocks/AlmIntegrationsServiceMock.ts | 4 ++ .../BitbucketImportRepositoryForm.tsx | 7 ---- .../BitbucketProjectAccordion.tsx | 17 +------- .../BitbucketProjectCreate.tsx | 39 ++++++------------- .../BitbucketProjectCreateRenderer.tsx | 7 +--- .../BitbucketServer/BitbucketRepositories.tsx | 4 +- .../BitbucketSearchResults.tsx | 11 +----- .../apps/create/project/CreateProjectPage.tsx | 2 +- .../create/project/__tests__/Bitbucket-it.tsx | 12 ++++++ 10 files changed, 52 insertions(+), 80 deletions(-) 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 451e20fbfb5..7e81ff101ba 100644 --- a/server/sonar-web/src/main/js/api/alm-integrations.ts +++ b/server/sonar-web/src/main/js/api/alm-integrations.ts @@ -118,16 +118,25 @@ export function getBitbucketServerRepositories( }); } -export function importBitbucketServerProject( - almSetting: string, - projectKey: string, - repositorySlug: string -): Promise<{ project: ProjectBase }> { - return postJSON('/api/alm_integrations/import_bitbucketserver_project', { - almSetting, - projectKey, - repositorySlug, - }).catch(throwGlobalError); +export function setupBitbucketServerProjectCreation(data: { + almSetting: string; + projectKey: string; + repositorySlug: string; +}) { + return (newCodeDefinitionType?: string, newCodeDefinitionValue?: string) => + importBitbucketServerProject({ ...data, newCodeDefinitionType, newCodeDefinitionValue }); +} + +export function importBitbucketServerProject(data: { + almSetting: string; + projectKey: string; + repositorySlug: string; + newCodeDefinitionType?: string; + newCodeDefinitionValue?: string; +}): Promise<{ project: ProjectBase }> { + return postJSON('/api/alm_integrations/import_bitbucketserver_project', data).catch( + throwGlobalError + ); } export function searchForBitbucketServerRepositories( 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 0a1002c8842..05a6d32f6b8 100644 --- a/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts @@ -58,6 +58,7 @@ import { searchForBitbucketServerRepositories, setAlmPersonalAccessToken, setupAzureProjectCreation, + setupBitbucketServerProjectCreation, } from '../alm-integrations'; export default class AlmIntegrationsServiceMock { @@ -204,6 +205,9 @@ export default class AlmIntegrationsServiceMock { .mocked(getBitbucketServerRepositories) .mockImplementation(this.getBitbucketServerRepositories); jest.mocked(importBitbucketServerProject).mockImplementation(this.importBitbucketServerProject); + jest + .mocked(setupBitbucketServerProjectCreation) + .mockReturnValue(() => this.importBitbucketServerProject()); jest .mocked(searchForBitbucketServerRepositories) .mockImplementation(this.searchForBitbucketServerRepositories); diff --git a/server/sonar-web/src/main/js/apps/create/project/BitbucketServer/BitbucketImportRepositoryForm.tsx b/server/sonar-web/src/main/js/apps/create/project/BitbucketServer/BitbucketImportRepositoryForm.tsx index 8b22d219f30..bee7ea6a447 100644 --- a/server/sonar-web/src/main/js/apps/create/project/BitbucketServer/BitbucketImportRepositoryForm.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/BitbucketServer/BitbucketImportRepositoryForm.tsx @@ -29,13 +29,11 @@ import { BitbucketProjectRepositories, BitbucketRepository, } from '../../../../types/alm-integration'; -import InstanceNewCodeDefinitionComplianceWarning from '../components/InstanceNewCodeDefinitionComplianceWarning'; import { CreateProjectModes } from '../types'; import BitbucketRepositories from './BitbucketRepositories'; import BitbucketSearchResults from './BitbucketSearchResults'; export interface BitbucketImportRepositoryFormProps { - disableRepositories: boolean; onSearch: (query: string) => void; onSelectRepository: (repo: BitbucketRepository) => void; projects?: BitbucketProject[]; @@ -47,7 +45,6 @@ export interface BitbucketImportRepositoryFormProps { export default function BitbucketImportRepositoryForm(props: BitbucketImportRepositoryFormProps) { const { - disableRepositories, projects = [], projectRepositories = {}, searchResults, @@ -80,8 +77,6 @@ export default function BitbucketImportRepositoryForm(props: BitbucketImportRepo return (
- - ) : ( void; onSelectRepository: (repo: BitbucketRepository) => void; open: boolean; @@ -43,14 +42,7 @@ export interface BitbucketProjectAccordionProps { } export default function BitbucketProjectAccordion(props: BitbucketProjectAccordionProps) { - const { - disableRepositories, - open, - project, - repositories, - selectedRepository, - showingAllRepositories, - } = props; + const { open, project, repositories, selectedRepository, showingAllRepositories } = props; const repositoryCount = repositories.length; @@ -119,12 +111,7 @@ export default function BitbucketProjectAccordion(props: BitbucketProjectAccordi ) : ( props.onSelectRepository(repo)} value={String(repo.id)} diff --git a/server/sonar-web/src/main/js/apps/create/project/BitbucketServer/BitbucketProjectCreate.tsx b/server/sonar-web/src/main/js/apps/create/project/BitbucketServer/BitbucketProjectCreate.tsx index 49f19542cb1..0613375131a 100644 --- a/server/sonar-web/src/main/js/apps/create/project/BitbucketServer/BitbucketProjectCreate.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/BitbucketServer/BitbucketProjectCreate.tsx @@ -21,8 +21,8 @@ import * as React from 'react'; import { getBitbucketServerProjects, getBitbucketServerRepositories, - importBitbucketServerProject, searchForBitbucketServerRepositories, + setupBitbucketServerProjectCreation, } from '../../../../api/alm-integrations'; import { Location, Router } from '../../../../components/hoc/withRouter'; import { @@ -32,20 +32,20 @@ import { } from '../../../../types/alm-integration'; import { AlmSettingsInstance } from '../../../../types/alm-settings'; import { DEFAULT_BBS_PAGE_SIZE } from '../constants'; +import { CreateProjectApiCallback } from '../types'; import BitbucketCreateProjectRenderer from './BitbucketProjectCreateRenderer'; interface Props { canAdmin: boolean; almInstances: AlmSettingsInstance[]; loadingBindings: boolean; - onProjectCreate: (projectKey: string) => void; location: Location; router: Router; + onProjectSetupDone: (createProject: CreateProjectApiCallback) => void; } interface State { selectedAlmInstance?: AlmSettingsInstance; - importing: boolean; loading: boolean; projects?: BitbucketProject[]; projectRepositories?: BitbucketProjectRepositories; @@ -61,10 +61,7 @@ export default class BitbucketProjectCreate extends React.PureComponent { const { selectedAlmInstance, selectedRepository } = this.state; - if (!selectedAlmInstance || !selectedRepository) { - return; + if (selectedAlmInstance && selectedRepository) { + this.props.onProjectSetupDone( + setupBitbucketServerProjectCreation({ + almSetting: selectedAlmInstance.key, + projectKey: selectedRepository.projectKey, + repositorySlug: selectedRepository.slug, + }) + ); } - - this.setState({ importing: true }); - importBitbucketServerProject( - selectedAlmInstance.key, - selectedRepository.projectKey, - selectedRepository.slug - ) - .then(({ project: { key } }) => { - if (this.mounted) { - this.setState({ importing: false }); - this.props.onProjectCreate(key); - } - }) - .catch(() => { - if (this.mounted) { - this.setState({ importing: false }); - } - }); }; handleSearch = (query: string) => { @@ -253,7 +238,6 @@ export default class BitbucketProjectCreate extends React.PureComponent void; onSearch: (query: string) => void; @@ -59,7 +57,6 @@ export default function BitbucketProjectCreateRenderer(props: BitbucketProjectCr almInstances, selectedAlmInstance, canAdmin, - importing, loading, projects, projectRepositories, @@ -76,10 +73,9 @@ export default function BitbucketProjectCreateRenderer(props: BitbucketProjectCr additionalActions={ !showPersonalAccessTokenForm && (
-