]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-22947 Force re-sync when auto-provisioning setting change (#11764)
authorSarath Nair <91882341+sarath-nair-sonarsource@users.noreply.github.com>
Thu, 26 Sep 2024 07:57:57 +0000 (09:57 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 26 Sep 2024 20:03:14 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-Github-it.tsx
server/sonar-web/src/main/js/queries/dop-translation.ts
server/sonar-web/src/main/js/queries/identity-provider/gitlab.ts

index 44bf87f1407465baaab3dcb717ec5a6cd04ffe7f..13a0f954738fdc36fb070b8c38e8650a0f693a77 100644 (file)
@@ -25,6 +25,7 @@ import { byLabelText, byRole, byText } from '~sonar-aligned/helpers/testSelector
 import ComputeEngineServiceMock from '../../../../../api/mocks/ComputeEngineServiceMock';
 import DopTranslationServiceMock from '../../../../../api/mocks/DopTranslationServiceMock';
 import GithubProvisioningServiceMock from '../../../../../api/mocks/GithubProvisioningServiceMock';
+import GitlabProvisioningServiceMock from '../../../../../api/mocks/GitlabProvisioningServiceMock';
 import SettingsServiceMock from '../../../../../api/mocks/SettingsServiceMock';
 import SystemServiceMock from '../../../../../api/mocks/SystemServiceMock';
 import { AvailableFeaturesContext } from '../../../../../app/components/available-features/AvailableFeaturesContext';
@@ -42,6 +43,7 @@ let system: SystemServiceMock;
 let settingsHandler: SettingsServiceMock;
 let computeEngineHandler: ComputeEngineServiceMock;
 let dopTranslationHandler: DopTranslationServiceMock;
+let gitlabHandler: GitlabProvisioningServiceMock;
 
 const mockedGitHubConfigurationResponse = mockGitHubConfiguration({
   apiUrl: 'API url',
@@ -56,6 +58,7 @@ beforeEach(() => {
   system = new SystemServiceMock();
   settingsHandler = new SettingsServiceMock();
   computeEngineHandler = new ComputeEngineServiceMock();
+  gitlabHandler = new GitlabProvisioningServiceMock();
 });
 
 afterEach(() => {
@@ -64,6 +67,7 @@ afterEach(() => {
   system.reset();
   computeEngineHandler.reset();
   dopTranslationHandler.reset();
+  gitlabHandler.reset();
 });
 
 const ghContainer = byRole('tabpanel', { name: 'github GitHub' });
index c2879fd1359db9cee90318607a42ffec3392ddf2..44180d545bb0ea4f1a3c0dc72dcf594e60f3f23e 100644 (file)
@@ -29,6 +29,8 @@ import {
   updateGitHubConfiguration,
 } from '../api/dop-translation';
 import { translate } from '../helpers/l10n';
+import { ProvisioningType } from '../types/provisioning';
+import { useSyncWithGitHubNow } from './identity-provider/github';
 
 /*
  * Project bindings
@@ -87,6 +89,7 @@ export function useCreateGitHubConfigurationMutation() {
 
 export function useUpdateGitHubConfigurationMutation() {
   const client = useQueryClient();
+  const { canSyncNow, synchronizeNow } = useSyncWithGitHubNow();
   return useMutation({
     mutationFn: ({
       gitHubConfiguration,
@@ -106,6 +109,9 @@ export function useUpdateGitHubConfigurationMutation() {
       });
       client.setQueryData(['dop-translation', 'github-configs', 'fetch'], gitHubConfiguration);
       client.invalidateQueries({ queryKey: ['identity_provider'] });
+      if (canSyncNow && gitHubConfiguration.provisioningType === ProvisioningType.auto) {
+        synchronizeNow();
+      }
       addGlobalSuccessMessage(translate('settings.authentication.form.settings.save_success'));
     },
   });
index a88cb9612b3c176f70eba7cf681dc0686dc3c298..59d56b0ef4a6cd1477c470461d6ac4dd0c136dc1 100644 (file)
@@ -36,7 +36,7 @@ import { translate } from '../../helpers/l10n';
 import { mapReactQueryResult } from '../../helpers/react-query';
 import { AlmSyncStatus, DevopsRolesMapping, ProvisioningType } from '../../types/provisioning';
 import { TaskStatuses, TaskTypes } from '../../types/tasks';
-import { createQueryHook, StaleTime } from '../common';
+import { StaleTime, createQueryHook } from '../common';
 
 export function useGitLabConfigurationsQuery() {
   return useQuery({
@@ -65,6 +65,8 @@ export function useCreateGitLabConfigurationMutation() {
 
 export function useUpdateGitLabConfigurationMutation() {
   const client = useQueryClient();
+  const { canSyncNow, synchronizeNow } = useSyncWithGitLabNow();
+
   return useMutation({
     mutationFn: ({
       id,
@@ -83,6 +85,9 @@ export function useUpdateGitLabConfigurationMutation() {
           total: 1,
         },
       });
+      if (canSyncNow && data.provisioningType === ProvisioningType.auto) {
+        synchronizeNow();
+      }
       addGlobalSuccessMessage(translate('settings.authentication.form.settings.save_success'));
     },
   });