aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorViktor Vorona <viktor.vorona@sonarsource.com>2023-08-14 13:07:45 +0200
committersonartech <sonartech@sonarsource.com>2023-08-15 20:02:41 +0000
commit4f7c8b3b77dd11e655b20fdf40654881d98176f3 (patch)
tree50ef984920cf873d9fc61cfd3e1c62f89ce3fd70 /server
parent7a81f137edc9b19852008d4f6582efc74c763e3c (diff)
downloadsonarqube-4f7c8b3b77dd11e655b20fdf40654881d98176f3.tar.gz
sonarqube-4f7c8b3b77dd11e655b20fdf40654881d98176f3.zip
SONAR-19870 Github sync warning message
Diffstat (limited to 'server')
-rw-r--r--server/sonar-web/src/main/js/api/mocks/AuthenticationServiceMock.ts5
-rw-r--r--server/sonar-web/src/main/js/app/components/GitHubSynchronisationWarning.tsx87
-rw-r--r--server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx16
-rw-r--r--server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-it.tsx14
-rw-r--r--server/sonar-web/src/main/js/types/provisioning.ts1
5 files changed, 90 insertions, 33 deletions
diff --git a/server/sonar-web/src/main/js/api/mocks/AuthenticationServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/AuthenticationServiceMock.ts
index a274646fa14..800cd0ef8a0 100644
--- a/server/sonar-web/src/main/js/api/mocks/AuthenticationServiceMock.ts
+++ b/server/sonar-web/src/main/js/api/mocks/AuthenticationServiceMock.ts
@@ -129,11 +129,11 @@ export default class AuthenticationServiceMock {
return Promise.resolve({ enabled: false });
}
- const nextSync = this.tasks.find((t: any) =>
+ const nextSync = this.tasks.find((t: Task) =>
[TaskStatuses.InProgress, TaskStatuses.Pending].includes(t.status)
);
const lastSync = this.tasks.find(
- (t: any) => ![TaskStatuses.InProgress, TaskStatuses.Pending].includes(t.status)
+ (t: Task) => ![TaskStatuses.InProgress, TaskStatuses.Pending].includes(t.status)
);
return Promise.resolve({
@@ -147,6 +147,7 @@ export default class AuthenticationServiceMock {
executionTimeMs: lastSync.executionTimeMs,
summary: lastSync.status === TaskStatuses.Success ? 'Test summary' : undefined,
errorMessage: lastSync.errorMessage,
+ warningMessage: lastSync.warnings?.join() ?? undefined,
}
: undefined,
});
diff --git a/server/sonar-web/src/main/js/app/components/GitHubSynchronisationWarning.tsx b/server/sonar-web/src/main/js/app/components/GitHubSynchronisationWarning.tsx
index 5b637c729df..0fafaea3e73 100644
--- a/server/sonar-web/src/main/js/app/components/GitHubSynchronisationWarning.tsx
+++ b/server/sonar-web/src/main/js/app/components/GitHubSynchronisationWarning.tsx
@@ -22,6 +22,7 @@ import * as React from 'react';
import { FormattedMessage } from 'react-intl';
import Link from '../../components/common/Link';
import CheckIcon from '../../components/icons/CheckIcon';
+import WarningIcon from '../../components/icons/WarningIcon';
import { Alert } from '../../components/ui/Alert';
import { translate, translateWithParameters } from '../../helpers/l10n';
import { useGitHubSyncStatusQuery } from '../../queries/identity-provider';
@@ -42,7 +43,7 @@ function LastSyncAlert({ info, short }: LastSyncProps) {
if (info === undefined) {
return null;
}
- const { finishedAt, errorMessage, status, summary } = info;
+ const { finishedAt, errorMessage, status, summary, warningMessage } = info;
const formattedDate = finishedAt ? formatDistance(new Date(finishedAt), new Date()) : '';
@@ -50,12 +51,33 @@ function LastSyncAlert({ info, short }: LastSyncProps) {
return status === TaskStatuses.Success ? (
<div>
<span className="authentication-enabled spacer-left">
- <CheckIcon className="spacer-right" />
+ {warningMessage ? (
+ <WarningIcon className="spacer-right" />
+ ) : (
+ <CheckIcon className="spacer-right" />
+ )}
</span>
<i>
- {translateWithParameters(
- 'settings.authentication.github.synchronization_successful',
- formattedDate
+ {warningMessage ? (
+ <FormattedMessage
+ id="settings.authentication.github.synchronization_successful.with_warning"
+ defaultMessage={translate(
+ 'settings.authentication.github.synchronization_successful.with_warning'
+ )}
+ values={{
+ date: formattedDate,
+ details: (
+ <Link to="../settings?category=authentication&tab=github">
+ {translate('settings.authentication.github.synchronization_details_link')}
+ </Link>
+ ),
+ }}
+ />
+ ) : (
+ translateWithParameters(
+ 'settings.authentication.github.synchronization_successful',
+ formattedDate
+ )
)}
</i>
</div>
@@ -67,7 +89,7 @@ function LastSyncAlert({ info, short }: LastSyncProps) {
values={{
details: (
<Link to="../settings?category=authentication&tab=github">
- {translate('settings.authentication.github.synchronization_failed_link')}
+ {translate('settings.authentication.github.synchronization_details_link')}
</Link>
),
}}
@@ -77,33 +99,38 @@ function LastSyncAlert({ info, short }: LastSyncProps) {
}
return (
- <Alert
- variant={status === TaskStatuses.Success ? 'success' : 'error'}
- role="alert"
- aria-live="assertive"
- >
- {status === TaskStatuses.Success ? (
- <>
- {translateWithParameters(
- 'settings.authentication.github.synchronization_successful',
- formattedDate
- )}
- <br />
- {summary ?? ''}
- </>
- ) : (
- <React.Fragment key={`synch-alert-${finishedAt}`}>
- <div>
+ <>
+ <Alert
+ variant={status === TaskStatuses.Success ? 'success' : 'error'}
+ role="alert"
+ aria-live="assertive"
+ >
+ {status === TaskStatuses.Success ? (
+ <>
{translateWithParameters(
- 'settings.authentication.github.synchronization_failed',
+ 'settings.authentication.github.synchronization_successful',
formattedDate
)}
- </div>
- <br />
- {errorMessage ?? ''}
- </React.Fragment>
- )}
- </Alert>
+ <br />
+ {summary ?? ''}
+ </>
+ ) : (
+ <React.Fragment key={`synch-alert-${finishedAt}`}>
+ <div>
+ {translateWithParameters(
+ 'settings.authentication.github.synchronization_failed',
+ formattedDate
+ )}
+ </div>
+ <br />
+ {errorMessage ?? ''}
+ </React.Fragment>
+ )}
+ </Alert>
+ <Alert variant="warning" role="alert" aria-live="assertive">
+ {warningMessage}
+ </Alert>
+ </>
);
}
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 d5a119ebbc1..b61e05b3f86 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
@@ -172,6 +172,8 @@ const ui = {
configurationValidityError: byRole('status', {
name: /github.configuration.validation.invalid/,
}),
+ syncWarning: byText(/Warning/),
+ syncSummary: byText(/Test summary/),
configurationValidityWarning: byRole('status', {
name: /github.configuration.validation.valid.short/,
}),
@@ -473,7 +475,7 @@ describe('Github tab', () => {
renderAuthentication([Feature.GithubProvisioning]);
await github.enableProvisioning(user);
expect(github.githubProvisioningSuccess.get()).toBeInTheDocument();
- expect(github.githubProvisioningButton.get()).toHaveTextContent('Test summary');
+ expect(github.syncSummary.get()).toBeInTheDocument();
});
it('should display a success status even when another task is pending', async () => {
@@ -777,6 +779,18 @@ describe('Github tab', () => {
expect(github.configurationValiditySuccess.get()).toBeInTheDocument();
expect(github.configurationValidityError.query()).not.toBeInTheDocument();
});
+
+ it('should show warning', async () => {
+ handler.addProvisioningTask({
+ status: TaskStatuses.Success,
+ warnings: ['Warning'],
+ });
+ renderAuthentication([Feature.GithubProvisioning]);
+ await github.enableProvisioning(user);
+
+ expect(await github.syncWarning.find()).toBeInTheDocument();
+ expect(github.syncSummary.get()).toBeInTheDocument();
+ });
});
});
diff --git a/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-it.tsx b/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-it.tsx
index 702e348f7c4..d7a0eda66de 100644
--- a/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-it.tsx
+++ b/server/sonar-web/src/main/js/apps/users/__tests__/UsersApp-it.tsx
@@ -128,6 +128,7 @@ const ui = {
githubProvisioningPending: byText(/synchronization_pending/),
githubProvisioningInProgress: byText(/synchronization_in_progress/),
githubProvisioningSuccess: byText(/synchronization_successful/),
+ githubProvisioningWarning: byText(/synchronization_successful.with_warning/),
githubProvisioningAlert: byText(/synchronization_failed_short/),
};
@@ -607,6 +608,19 @@ describe('in manage mode', () => {
expect(ui.githubProvisioningSuccess.query()).not.toBeInTheDocument();
expect(ui.githubProvisioningInProgress.query()).not.toBeInTheDocument();
});
+
+ it('should display an warning alert', async () => {
+ const warningMessage = 'Very long warning about something that user is not interested in';
+ authenticationHandler.addProvisioningTask({
+ status: TaskStatuses.Success,
+ warnings: [warningMessage],
+ });
+ renderUsersApp([Feature.GithubProvisioning]);
+ await act(async () => expect(await ui.githubProvisioningWarning.find()).toBeInTheDocument());
+ // We don't want to display the full warning message.
+ expect(screen.queryByText(warningMessage)).not.toBeInTheDocument();
+ expect(ui.githubProvisioningWarning.byRole('link').get()).toBeInTheDocument();
+ });
});
});
diff --git a/server/sonar-web/src/main/js/types/provisioning.ts b/server/sonar-web/src/main/js/types/provisioning.ts
index 521fdb8de44..81ff4c6d1c9 100644
--- a/server/sonar-web/src/main/js/types/provisioning.ts
+++ b/server/sonar-web/src/main/js/types/provisioning.ts
@@ -32,6 +32,7 @@ export type GithubStatusEnabled = {
executionTimeMs: number;
finishedAt: number;
startedAt: number;
+ warningMessage?: string;
} & (
| {
status: TaskStatuses.Success;