]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19337 Improve GitHub sync message for one org matching and fix failed status
authorMathieu Suen <mathieu.suen@sonarsource.com>
Wed, 31 May 2023 14:43:53 +0000 (16:43 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 1 Jun 2023 20:02:58 +0000 (20:02 +0000)
server/sonar-web/src/main/js/apps/settings/components/authentication/ConfigurationForm.tsx
server/sonar-web/src/main/js/apps/settings/components/authentication/GitHubConfigurationValidity.tsx
server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx
server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useGithubConfiguration.ts
server/sonar-web/src/main/js/types/provisioning.ts
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index f6888c38ed4bc4cb4ca37ad44d228e1790ceb79f..153c615457a652964fc337caa61a2710bb2cbf6c 100644 (file)
@@ -121,10 +121,13 @@ export default function ConfigurationForm(props: Props) {
           >
             <Alert variant={hasLegacyConfiguration ? 'warning' : 'info'}>
               <FormattedMessage
-                id={`settings.authentication.${hasLegacyConfiguration ? 'legacy_help' : 'help'}`}
+                id={`settings.authentication.${
+                  hasLegacyConfiguration ? 'legacy_help.github' : 'help'
+                }`}
                 defaultMessage={translate(
-                  `settings.authentication.${hasLegacyConfiguration ? 'legacy_help' : 'help'}`,
-                  tab
+                  `settings.authentication.${
+                    hasLegacyConfiguration ? 'legacy_help.github' : 'help'
+                  }`
                 )}
                 values={{
                   link: (
index b3e07c92cec574e292cc77e922ecd1eeadbde7d9..78eab7a5dc19e4c6c3617870d4a92c9c07546330 100644 (file)
@@ -66,18 +66,20 @@ function GitHubConfigurationValidity({ isAutoProvisioning }: Props) {
     const invalidOrgs =
       isValidApp && isAutoProvisioning && data
         ? data.installations.filter(
-            (org) => org.autoProvisioning.status === GitHubProvisioningStatus.Error
+            (org) => org.autoProvisioning.status === GitHubProvisioningStatus.Failed
           )
         : [];
 
     if (isValidApp && invalidOrgs.length === 0) {
       setMessages([
         translateWithParameters(
-          `${intlPrefix}.valid${data.installations.length > 1 ? '.multiple_orgs' : ''}`,
+          `${intlPrefix}.valid${data.installations.length === 1 ? '_one' : ''}`,
           isAutoProvisioning
             ? translate('settings.authentication.github.form.provisioning_with_github_short')
             : translate('settings.authentication.form.provisioning_at_login_short'),
-          data.installations.length
+          data.installations.length === 1
+            ? data.installations[0].organization
+            : data.installations.length
         ),
       ]);
       setAlertVariant('success');
@@ -140,7 +142,7 @@ function GitHubConfigurationValidity({ isAutoProvisioning }: Props) {
                   />
                   <span className="sw-ml-2">{inst.organization}</span>
                   {isAutoProvisioning &&
-                    inst.autoProvisioning.status === GitHubProvisioningStatus.Error && (
+                    inst.autoProvisioning.status === GitHubProvisioningStatus.Failed && (
                       <span> - {inst.autoProvisioning.errorMessage}</span>
                     )}
                 </li>
index fd56ab5477fca8881d61dcdd7b71e61ff8c754ab..02a8b996a332a983a7072b25b33af370fb72e2c4 100644 (file)
@@ -548,11 +548,11 @@ describe('Github tab', () => {
       handler.setConfigurationValidity({
         application: {
           jit: {
-            status: GitHubProvisioningStatus.Error,
+            status: GitHubProvisioningStatus.Failed,
             errorMessage,
           },
           autoProvisioning: {
-            status: GitHubProvisioningStatus.Error,
+            status: GitHubProvisioningStatus.Failed,
             errorMessage,
           },
         },
@@ -578,7 +578,7 @@ describe('Github tab', () => {
             status: GitHubProvisioningStatus.Success,
           },
           autoProvisioning: {
-            status: GitHubProvisioningStatus.Error,
+            status: GitHubProvisioningStatus.Failed,
             errorMessage,
           },
         },
@@ -615,7 +615,7 @@ describe('Github tab', () => {
           { organization: 'org1', autoProvisioning: { status: GitHubProvisioningStatus.Success } },
           {
             organization: 'org2',
-            autoProvisioning: { status: GitHubProvisioningStatus.Error, errorMessage },
+            autoProvisioning: { status: GitHubProvisioningStatus.Failed, errorMessage },
           },
         ],
       });
@@ -651,11 +651,11 @@ describe('Github tab', () => {
       handler.setConfigurationValidity({
         application: {
           jit: {
-            status: GitHubProvisioningStatus.Error,
+            status: GitHubProvisioningStatus.Failed,
             errorMessage,
           },
           autoProvisioning: {
-            status: GitHubProvisioningStatus.Error,
+            status: GitHubProvisioningStatus.Failed,
             errorMessage,
           },
         },
index a99702ca1aefa8a92d9aeed9ff378aec9f0370de..7b1d1121478f5bbca416b27e394920fd27d106e7 100644 (file)
@@ -24,6 +24,7 @@ import { AvailableFeaturesContext } from '../../../../../app/components/availabl
 import { Feature } from '../../../../../types/features';
 import { ExtendedSettingDefinition } from '../../../../../types/settings';
 import {
+  useCheckGitHubConfigQuery,
   useGithubStatusQuery,
   useToggleGithubProvisioningMutation,
 } from '../queries/identity-provider';
@@ -60,6 +61,7 @@ export default function useGithubConfiguration(definitions: ExtendedSettingDefin
     Feature.GithubProvisioning
   );
   const { data: githubProvisioningStatus } = useGithubStatusQuery();
+  const { refetch } = useCheckGitHubConfigQuery();
   const toggleGithubProvisioning = useToggleGithubProvisioningMutation();
   const [newGithubProvisioningStatus, setNewGithubProvisioningStatus] = useState<boolean>();
   const hasGithubProvisioningConfigChange =
@@ -78,6 +80,8 @@ export default function useGithubConfiguration(definitions: ExtendedSettingDefin
 
   const reload = useCallback(async () => {
     await reloadConfig();
+    // Temporary solution that will be solved once we migrate to react-query
+    refetch();
   }, [reloadConfig]);
 
   const changeProvisioning = async () => {
index 0ee9606431662e1eceb00a8e967bfaf392e0eecb..a94b6f84a210a36a2bbb72aa0388f24201258306 100644 (file)
@@ -50,7 +50,7 @@ export type GithubStatus = GithubStatusDisabled | GithubStatusEnabled;
 
 export enum GitHubProvisioningStatus {
   Success = 'SUCCESS',
-  Error = 'ERROR',
+  Failed = 'FAILED',
 }
 
 type GitHubProvisioning =
@@ -59,7 +59,7 @@ type GitHubProvisioning =
       errorMessage?: never;
     }
   | {
-      status: GitHubProvisioningStatus.Error;
+      status: GitHubProvisioningStatus.Failed;
       errorMessage: string;
     };
 
index 2f0bc0fe6eff57946b4704ea7b0f51a10e379f85..58dfb084222f6e4cc2bd82bda67937eddf005d8d 100644 (file)
@@ -1398,8 +1398,8 @@ settings.authentication.github.synchronization_failed_link=More details
 settings.authentication.github.configuration.validation.details=View details
 settings.authentication.github.configuration.validation.test=Test configuration
 settings.authentication.github.configuration.validation.loading=Checking the configuration
-settings.authentication.github.configuration.validation.valid=Configuration is valid for {0}.
-settings.authentication.github.configuration.validation.valid.multiple_orgs=Configuration is valid for {0}. {1} organizations will be synced.
+settings.authentication.github.configuration.validation.valid=Configuration is valid for {0}. {1} organizations will be synced.
+settings.authentication.github.configuration.validation.valid_one=Configuration is valid for {0}. Organization '{1}' will be synced.
 settings.authentication.github.configuration.validation.invalid=Configuration is invalid. {0}
 settings.authentication.github.configuration.validation.invalid_org=Organization "{0}" has the following error: {1}
 settings.authentication.github.configuration.validation.details.title=Configuration validity: