From 4a59ebc98cfcf6db8093e90cf1fdaf5f1c0095c7 Mon Sep 17 00:00:00 2001 From: Andrey Luiz Date: Mon, 12 Jun 2023 11:29:04 +0200 Subject: [PATCH] SONAR-19454 New code definition is made part of GitHub project onboarding --- .../src/main/js/api/alm-integrations.ts | 27 +++--- .../api/mocks/AlmIntegrationsServiceMock.ts | 2 + .../apps/create/project/CreateProjectPage.tsx | 2 +- .../project/Github/GitHubProjectCreate.tsx | 33 +++---- .../Github/GitHubProjectCreateRenderer.tsx | 90 +++++++++---------- .../create/project/__tests__/GitHub-it.tsx | 11 +++ 6 files changed, 82 insertions(+), 83 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 bd225e1e2dc..246da52cda2 100644 --- a/server/sonar-web/src/main/js/api/alm-integrations.ts +++ b/server/sonar-web/src/main/js/api/alm-integrations.ts @@ -190,16 +190,23 @@ export function importBitbucketCloudRepository(data: { return postJSON('/api/alm_integrations/import_bitbucketcloud_repo', data).catch(throwGlobalError); } -export function importGithubRepository( - almSetting: string, - organization: string, - repositoryKey: string -): Promise<{ project: ProjectBase }> { - return postJSON('/api/alm_integrations/import_github_project', { - almSetting, - organization, - repositoryKey, - }).catch(throwGlobalError); +export function setupGithubProjectCreation(data: { + almSetting: string; + organization: string; + repositoryKey: string; +}) { + return (newCodeDefinitionType?: string, newCodeDefinitionValue?: string) => + importGithubRepository({ ...data, newCodeDefinitionType, newCodeDefinitionValue }); +} + +export function importGithubRepository(data: { + almSetting: string; + organization: string; + repositoryKey: string; + newCodeDefinitionType?: string; + newCodeDefinitionValue?: string; +}): Promise<{ project: ProjectBase }> { + return postJSON('/api/alm_integrations/import_github_project', data).catch(throwGlobalError); } export function getGithubOrganizations( 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 e34143b5c02..6adbdcd7ec8 100644 --- a/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/AlmIntegrationsServiceMock.ts @@ -61,6 +61,7 @@ import { setupBitbucketCloudProjectCreation, setupBitbucketServerProjectCreation, setupGitlabProjectCreation, + setupGithubProjectCreation, } from '../alm-integrations'; export default class AlmIntegrationsServiceMock { @@ -200,6 +201,7 @@ export default class AlmIntegrationsServiceMock { jest.mocked(searchAzureRepositories).mockImplementation(this.searchAzureRepositories); jest.mocked(setupAzureProjectCreation).mockReturnValue(() => this.importAzureRepository()); jest.mocked(importAzureRepository).mockImplementation(this.importAzureRepository); + jest.mocked(setupGithubProjectCreation).mockReturnValue(() => this.importGithubRepository()); jest.mocked(importGithubRepository).mockImplementation(this.importGithubRepository); jest .mocked(searchForBitbucketCloudRepositories) diff --git a/server/sonar-web/src/main/js/apps/create/project/CreateProjectPage.tsx b/server/sonar-web/src/main/js/apps/create/project/CreateProjectPage.tsx index 0a8d1add2b6..afa24320ec4 100644 --- a/server/sonar-web/src/main/js/apps/create/project/CreateProjectPage.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/CreateProjectPage.tsx @@ -243,7 +243,7 @@ export class CreateProjectPage extends React.PureComponent diff --git a/server/sonar-web/src/main/js/apps/create/project/Github/GitHubProjectCreate.tsx b/server/sonar-web/src/main/js/apps/create/project/Github/GitHubProjectCreate.tsx index a07808a46ba..4e625e2547f 100644 --- a/server/sonar-web/src/main/js/apps/create/project/Github/GitHubProjectCreate.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/Github/GitHubProjectCreate.tsx @@ -24,7 +24,7 @@ import { getGithubClientId, getGithubOrganizations, getGithubRepositories, - importGithubRepository, + setupGithubProjectCreation, } from '../../../../api/alm-integrations'; import { Location, Router } from '../../../../components/hoc/withRouter'; import { getHostUrl } from '../../../../helpers/urls'; @@ -32,11 +32,12 @@ import { GithubOrganization, GithubRepository } from '../../../../types/alm-inte import { AlmKeys, AlmSettingsInstance } from '../../../../types/alm-settings'; import { Paging } from '../../../../types/types'; import GitHubProjectCreateRenderer from './GitHubProjectCreateRenderer'; +import { CreateProjectApiCallback } from '../types'; interface Props { canAdmin: boolean; loadingBindings: boolean; - onProjectCreate: (projectKey: string) => void; + onProjectSetupDone: (createProject: CreateProjectApiCallback) => void; almInstances: AlmSettingsInstance[]; location: Location; router: Router; @@ -44,7 +45,6 @@ interface Props { interface State { error: boolean; - importing: boolean; loadingOrganizations: boolean; loadingRepositories: boolean; organizations: GithubOrganization[]; @@ -66,7 +66,6 @@ export default class GitHubProjectCreate extends React.Component { this.state = { error: false, - importing: false, loadingOrganizations: true, loadingRepositories: false, organizations: [], @@ -269,25 +268,17 @@ export default class GitHubProjectCreate extends React.Component { } }; - handleImportRepository = async () => { + handleImportRepository = () => { const { selectedOrganization, selectedRepository, selectedAlmInstance } = this.state; if (selectedAlmInstance && selectedOrganization && selectedRepository) { - this.setState({ importing: true }); - - try { - const { project } = await importGithubRepository( - selectedAlmInstance.key, - selectedOrganization.key, - selectedRepository.key - ); - - this.props.onProjectCreate(project.key); - } finally { - if (this.mounted) { - this.setState({ importing: false }); - } - } + this.props.onProjectSetupDone( + setupGithubProjectCreation({ + almSetting: selectedAlmInstance.key, + organization: selectedOrganization.key, + repositoryKey: selectedRepository.key, + }) + ); } }; @@ -306,7 +297,6 @@ export default class GitHubProjectCreate extends React.Component { const { canAdmin, loadingBindings, almInstances } = this.props; const { error, - importing, loadingOrganizations, loadingRepositories, organizations, @@ -322,7 +312,6 @@ export default class GitHubProjectCreate extends React.Component { - !!repository.sqProjectKey || loadingRepositories || importing; + !!repository.sqProjectKey || loadingRepositories; return ( selectedOrganization && @@ -175,7 +172,6 @@ export default function GitHubProjectCreateRenderer(props: GitHubProjectCreateRe const { canAdmin, error, - importing, loadingBindings, loadingOrganizations, organizations, @@ -195,10 +191,9 @@ export default function GitHubProjectCreateRenderer(props: GitHubProjectCreateRe additionalActions={ selectedOrganization && (
-