From 378ceb7b2eba6b6ab3a582374631b64fc1832854 Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Wed, 31 May 2023 16:43:53 +0200 Subject: [PATCH] SONAR-19337 Improve GitHub sync message for one org matching and fix failed status --- .../components/authentication/ConfigurationForm.tsx | 9 ++++++--- .../authentication/GitHubConfigurationValidity.tsx | 10 ++++++---- .../authentication/__tests__/Authentication-it.tsx | 12 ++++++------ .../authentication/hook/useGithubConfiguration.ts | 4 ++++ server/sonar-web/src/main/js/types/provisioning.ts | 4 ++-- .../main/resources/org/sonar/l10n/core.properties | 4 ++-- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/ConfigurationForm.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/ConfigurationForm.tsx index f6888c38ed4..153c615457a 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/ConfigurationForm.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/ConfigurationForm.tsx @@ -121,10 +121,13 @@ export default function ConfigurationForm(props: Props) { > 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) { /> {inst.organization} {isAutoProvisioning && - inst.autoProvisioning.status === GitHubProvisioningStatus.Error && ( + inst.autoProvisioning.status === GitHubProvisioningStatus.Failed && ( - {inst.autoProvisioning.errorMessage} )} diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx index fd56ab5477f..02a8b996a33 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx @@ -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, }, }, diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useGithubConfiguration.ts b/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useGithubConfiguration.ts index a99702ca1ae..7b1d1121478 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useGithubConfiguration.ts +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useGithubConfiguration.ts @@ -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(); 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 () => { diff --git a/server/sonar-web/src/main/js/types/provisioning.ts b/server/sonar-web/src/main/js/types/provisioning.ts index 0ee96064316..a94b6f84a21 100644 --- a/server/sonar-web/src/main/js/types/provisioning.ts +++ b/server/sonar-web/src/main/js/types/provisioning.ts @@ -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; }; 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 2f0bc0fe6ef..58dfb084222 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -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: -- 2.39.5