From 63bf4c43f1bda72919b5f0a9d69b3e480186a4e0 Mon Sep 17 00:00:00 2001 From: guillaume-peoch-sonarsource Date: Wed, 14 Jun 2023 12:22:11 +0200 Subject: [PATCH] SONAR-17782 Check server base URL is set in DevOps platform settings --- .../almIntegration/AlmIntegrationRenderer.tsx | 26 ++++++++++++++++- .../__tests__/AlmIntegration-it.tsx | 29 +++++++++++++++++++ .../resources/org/sonar/l10n/core.properties | 2 ++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegrationRenderer.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegrationRenderer.tsx index 0c618d4cfcd..59965b85516 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegrationRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegrationRenderer.tsx @@ -18,7 +18,10 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; +import { FormattedMessage } from 'react-intl'; +import Link from '../../../../components/common/Link'; import BoxedTabs from '../../../../components/controls/BoxedTabs'; +import { Alert } from '../../../../components/ui/Alert'; import { translate } from '../../../../helpers/l10n'; import { getBaseUrl } from '../../../../helpers/system'; import { @@ -26,7 +29,9 @@ import { AlmSettingsBindingDefinitions, AlmSettingsBindingStatus, } from '../../../../types/alm-settings'; +import { SettingsKey } from '../../../../types/settings'; import { Dict } from '../../../../types/types'; +import { useGetValuesQuery } from '../../queries/settings'; import { AlmTabs } from './AlmIntegration'; import AlmTab from './AlmTab'; import DeleteModal from './DeleteModal'; @@ -128,13 +133,32 @@ export default function AlmIntegrationRenderer(props: AlmIntegrationRendererProp [AlmKeys.BitbucketServer]: [...definitions.bitbucket, ...definitions.bitbucketcloud], }; + const { data, isLoading } = useGetValuesQuery([SettingsKey.ServerBaseUrl]); + const hasServerBaseUrl = data?.length === 1 && data[0].value !== undefined; + return ( <>

{translate('settings.almintegration.title')}

-
+ {!hasServerBaseUrl && !isLoading && branchesEnabled && ( + + + {translate('settings.almintegration.empty.server_base_url.setting_link')} + + ), + }} + /> + + )} + +
{translate('settings.almintegration.description')}
diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmIntegration-it.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmIntegration-it.tsx index c811df5d983..c8b74e853e5 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmIntegration-it.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmIntegration-it.tsx @@ -21,23 +21,51 @@ import { screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import React from 'react'; import AlmSettingsServiceMock from '../../../../../api/mocks/AlmSettingsServiceMock'; +import SettingsServiceMock from '../../../../../api/mocks/SettingsServiceMock'; import { AvailableFeaturesContext } from '../../../../../app/components/available-features/AvailableFeaturesContext'; import { renderComponent } from '../../../../../helpers/testReactTestingUtils'; import { byRole, byText } from '../../../../../helpers/testSelector'; import { AlmKeys } from '../../../../../types/alm-settings'; import { Feature } from '../../../../../types/features'; +import { SettingsKey } from '../../../../../types/settings'; import AlmIntegration from '../AlmIntegration'; jest.mock('../../../../../api/alm-settings'); +jest.mock('../../../../../api/settings'); let almSettings: AlmSettingsServiceMock; +let settings: SettingsServiceMock; beforeAll(() => { almSettings = new AlmSettingsServiceMock(); + settings = new SettingsServiceMock(); }); afterEach(() => { almSettings.reset(); + settings.reset(); +}); + +it('should not display the serverBaseURL message when it is defined', async () => { + const { ui } = getPageObjects(); + settings.set(SettingsKey.ServerBaseUrl, 'http://localhost:9000'); + renderAlmIntegration([Feature.BranchSupport]); + expect(await ui.almHeading.find()).toBeInTheDocument(); + expect(ui.serverBaseUrlMissingInformation.query()).not.toBeInTheDocument(); +}); + +it('should not display the serverBaseURL message for Community edition', async () => { + const { ui } = getPageObjects(); + renderAlmIntegration(); + expect(await ui.almHeading.find()).toBeInTheDocument(); + expect(ui.serverBaseUrlMissingInformation.query()).not.toBeInTheDocument(); +}); + +it('should display the serverBaseURL message when it is not defined', async () => { + const { ui } = getPageObjects(); + renderAlmIntegration([Feature.BranchSupport]); + + expect(await ui.serverBaseUrlMissingInformation.find()).toBeInTheDocument(); }); describe('github tab', () => { @@ -155,6 +183,7 @@ function getPageObjects() { const ui = { almHeading: byRole('heading', { name: 'settings.almintegration.title' }), + serverBaseUrlMissingInformation: byText('settings.almintegration.empty.server_base_url'), emptyIntro: (almKey: AlmKeys) => byText(`settings.almintegration.empty.${almKey}`), createConfigurationButton: byRole('button', { name: 'settings.almintegration.create' }), tab: (almKey: AlmKeys) => 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 5aacd5992a6..0853667c347 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1273,6 +1273,8 @@ settings.projects.change_visibility_form.submit=Change Default Visibility settings.almintegration.title=DevOps Platform Integrations settings.almintegration.description=DevOps Platform integrations allow SonarQube to interact with your DevOps Platform. This enables things like authentication, or providing analysis details and a Quality Gate to your Pull Requests directly in your DevOps Platform's interface. +settings.almintegration.empty.server_base_url=You need to set the Server Base URL in General > {serverBaseUrl} to have correct links from the DevOps Platform to your SonarQube instance. +settings.almintegration.empty.server_base_url.setting_link=Server Base URL settings.almintegration.tab.github=GitHub settings.almintegration.tab.bitbucket=Bitbucket settings.almintegration.tab.azure=Azure DevOps -- 2.39.5