From 28ff86fcd8312d8e6b61a679106df554bcea072d Mon Sep 17 00:00:00 2001 From: Sarath Nair <91882341+sarath-nair-sonarsource@users.noreply.github.com> Date: Mon, 26 Aug 2024 09:41:34 +0200 Subject: [PATCH] SONAR-22559 Show provisioning status for gitlab project (#11601) --- .../overview/components/EmptyOverview.tsx | 17 ++++++-- .../components/__tests__/App-test.tsx | 40 +++++++++++++++++-- server/sonar-web/src/main/js/types/tasks.ts | 1 + .../resources/org/sonar/l10n/core.properties | 2 +- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/overview/components/EmptyOverview.tsx b/server/sonar-web/src/main/js/apps/overview/components/EmptyOverview.tsx index abf12138c2e..a8df895e419 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/EmptyOverview.tsx +++ b/server/sonar-web/src/main/js/apps/overview/components/EmptyOverview.tsx @@ -32,6 +32,7 @@ import { translate, translateWithParameters } from '../../../helpers/l10n'; import { getProjectTutorialLocation } from '../../../helpers/urls'; import { hasGlobalPermission } from '../../../helpers/users'; import { useTaskForComponentQuery } from '../../../queries/component'; +import { AlmKeys } from '../../../types/alm-settings'; import { BranchLike } from '../../../types/branch-like'; import { Permissions } from '../../../types/permissions'; import { TaskTypes } from '../../../types/tasks'; @@ -57,10 +58,17 @@ export function EmptyOverview(props: Readonly) { const hasQueuedAnalyses = data && data.queue.filter((task) => task.type === TaskTypes.Report).length > 0; + let permissionInSyncFor: AlmKeys.GitHub | AlmKeys.GitLab = AlmKeys.GitHub; + const hasPermissionSyncInProgess = data && - data.queue.filter((task) => task.type === TaskTypes.GithubProjectPermissionsProvisioning) - .length > 0; + data.queue.filter((task) => { + if (task.type === TaskTypes.GitlabProjectPermissionsProvisioning) { + permissionInSyncFor = AlmKeys.GitLab; + return true; + } + return task.type === TaskTypes.GithubProjectPermissionsProvisioning; + }).length > 0; React.useEffect(() => { if (currentUserCanScanProject || !isLoggedIn(currentUser)) { @@ -102,7 +110,10 @@ export function EmptyOverview(props: Readonly) { - {translate('provisioning.permission_synch_in_progress')} + {translateWithParameters( + 'provisioning.permission_synch_in_progress', + translate('alm', permissionInSyncFor), + )} diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.tsx index e3f9e6e096e..b8b7cca42d3 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.tsx @@ -119,7 +119,7 @@ describe('Permission provisioning', () => { afterEach(() => { jest.useRealTimers(); }); - it('should render warning when permission is sync', async () => { + it('should render warning when permission is sync for github', async () => { handlerCe.addTask( mockTask({ componentKey: 'my-project', @@ -132,7 +132,7 @@ describe('Permission provisioning', () => { jest.runOnlyPendingTimers(); expect( - await screen.findByText('provisioning.permission_synch_in_progress'), + await screen.findByText('provisioning.permission_synch_in_progress.alm.github'), ).toBeInTheDocument(); handlerCe.clearTasks(); @@ -148,7 +148,41 @@ describe('Permission provisioning', () => { await waitFor(() => { expect( - screen.queryByText('provisioning.permission_synch_in_progress'), + screen.queryByText('provisioning.permission_synch_in_progress.alm.github'), + ).not.toBeInTheDocument(); + }); + }); + + it('should render warning when permission is sync for gitlab', async () => { + handlerCe.addTask( + mockTask({ + componentKey: 'my-project', + type: TaskTypes.GitlabProjectPermissionsProvisioning, + status: TaskStatuses.InProgress, + }), + ); + + renderApp(); + + jest.runOnlyPendingTimers(); + expect( + await screen.findByText('provisioning.permission_synch_in_progress.alm.gitlab'), + ).toBeInTheDocument(); + + handlerCe.clearTasks(); + handlerCe.addTask( + mockTask({ + componentKey: 'my-project', + type: TaskTypes.GitlabProjectPermissionsProvisioning, + status: TaskStatuses.Success, + }), + ); + + jest.runOnlyPendingTimers(); + + await waitFor(() => { + expect( + screen.queryByText('provisioning.permission_synch_in_progress.alm.gitlab'), ).not.toBeInTheDocument(); }); }); diff --git a/server/sonar-web/src/main/js/types/tasks.ts b/server/sonar-web/src/main/js/types/tasks.ts index 83d73da3cc1..e1ce9b92992 100644 --- a/server/sonar-web/src/main/js/types/tasks.ts +++ b/server/sonar-web/src/main/js/types/tasks.ts @@ -23,6 +23,7 @@ export enum TaskTypes { GithubProvisioning = 'GITHUB_AUTH_PROVISIONING', GithubProjectPermissionsProvisioning = 'GITHUB_PROJECT_PERMISSIONS_PROVISIONING', GitlabProvisioning = 'GITLAB_AUTH_PROVISIONING', + GitlabProjectPermissionsProvisioning = 'GITLAB_PROJECT_PERMISSIONS_PROVISIONING', AppRefresh = 'APP_REFRESH', ViewRefresh = 'VIEW_REFRESH', ProjectExport = 'PROJECT_EXPORT', diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index b99581de2ac..84d4aaab267 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -2808,7 +2808,7 @@ provisioning.no_analysis_on_main_branch.bad_configuration="{0}" branch has not b provisioning.only_provisioned=Only Provisioned provisioning.only_provisioned.tooltip=Provisioned projects are projects that have been created, but have not been analyzed yet. provisioning.no_analysis.application=No analysis has been performed since creation. Analyze a project to see information here. -provisioning.permission_synch_in_progress=Project permissions are being synchronized from GitHub. +provisioning.permission_synch_in_progress=Project permissions are being synchronized from {0}. #------------------------------------------------------------------------------ -- 2.39.5