]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17782 Check server base URL is set in DevOps platform settings
authorguillaume-peoch-sonarsource <guillaume.peoch@sonarsource.com>
Wed, 14 Jun 2023 10:22:11 +0000 (12:22 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 15 Jun 2023 20:03:02 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegrationRenderer.tsx
server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmIntegration-it.tsx
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 0c618d4cfcd85bb242715e73d697cabf2e1be345..59965b8551600ccc1a272504ff5d420e8de2e69c 100644 (file)
  * 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 (
     <>
       <header className="page-header">
         <h1 className="page-title">{translate('settings.almintegration.title')}</h1>
       </header>
 
-      <div className="markdown small spacer-top big-spacer-bottom">
+      {!hasServerBaseUrl && !isLoading && branchesEnabled && (
+        <Alert variant="warning">
+          <FormattedMessage
+            id="settings.almintegration.empty.server_base_url"
+            defaultMessage={translate('settings.almintegration.empty.server_base_url')}
+            values={{
+              serverBaseUrl: (
+                <Link to="../settings?category=general#sonar.core.serverBaseURL">
+                  {translate('settings.almintegration.empty.server_base_url.setting_link')}
+                </Link>
+              ),
+            }}
+          />
+        </Alert>
+      )}
+
+      <div className="markdown small big-spacer-top big-spacer-bottom">
         {translate('settings.almintegration.description')}
       </div>
 
index c811df5d98319b83c49e2cfb2af61b0f2a9e6023..c8b74e853e53ccc046069668cace7ced5267d8da 100644 (file)
@@ -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) =>
index 5aacd5992a66c67f3cf34ed2c0cc28042eab8aed..0853667c3476c62665c93883aca496fe44807754 100644 (file)
@@ -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