Procházet zdrojové kódy

SONAR-11262 Add branch name in failed analysis notif

tags/7.5
Grégoire Aubert před 5 roky
rodič
revize
783e6e08ec

+ 1
- 0
server/sonar-web/src/main/js/app/components/ComponentContainer.tsx Zobrazit soubor

@@ -337,6 +337,7 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
component={component}
currentBranchLike={branchLike}
currentTask={currentTask}
currentTaskOnSameBranch={currentTask && this.isSameBranch(currentTask, branchLike)}
isInProgress={isInProgress}
isPending={isPending}
location={this.props.location}

+ 2
- 0
server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx Zobrazit soubor

@@ -35,6 +35,7 @@ interface Props {
currentBranchLike: BranchLike | undefined;
component: Component;
currentTask?: Task;
currentTaskOnSameBranch?: boolean;
isInProgress?: boolean;
isPending?: boolean;
location: {};
@@ -74,6 +75,7 @@ export default class ComponentNav extends React.PureComponent<Props> {
<ComponentNavBgTaskNotif
component={component}
currentTask={currentTask}
currentTaskOnSameBranch={this.props.currentTaskOnSameBranch}
isInProgress={isInProgress}
isPending={isPending}
/>

+ 32
- 18
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBgTaskNotif.tsx Zobrazit soubor

@@ -31,35 +31,38 @@ import { hasMessage, translate } from '../../../../helpers/l10n';
interface Props {
component: Component;
currentTask?: Task;
currentTaskOnSameBranch?: boolean;
isInProgress?: boolean;
isPending?: boolean;
}

export default class ComponentNavBgTaskNotif extends React.PureComponent<Props> {
renderMessage(messageKey: string, status?: string) {
renderMessage(messageKey: string, status?: string, branch?: string) {
const { component } = this.props;
const canSeeBackgroundTasks =
component.configuration && component.configuration.showBackgroundTasks;
const bgTaskUrl = getComponentBackgroundTaskUrl(component.key, status);

let url;
if (canSeeBackgroundTasks) {
return (
<FormattedMessage
defaultMessage={translate(messageKey, 'admin')}
id={messageKey + '.admin'}
values={{
url: <Link to={bgTaskUrl}>{translate('background_tasks.page')}</Link>
}}
/>
messageKey += '.admin';
url = (
<Link to={getComponentBackgroundTaskUrl(component.key, status)}>
{translate('background_tasks.page')}
</Link>
);
}

return <span>{translate(messageKey)}</span>;
return (
<FormattedMessage
defaultMessage={translate(messageKey)}
id={messageKey}
values={{ branch, url }}
/>
);
}

render() {
const { currentTask, isInProgress, isPending } = this.props;

const { currentTask, currentTaskOnSameBranch, isInProgress, isPending } = this.props;
if (isInProgress) {
return (
<NavBarNotif className="alert alert-info">
@@ -81,12 +84,23 @@ export default class ComponentNavBgTaskNotif extends React.PureComponent<Props>
) {
return <ComponentNavLicenseNotif currentTask={currentTask} />;
}
const branch =
currentTask.branch ||
`${currentTask.pullRequest}${
currentTask.pullRequestTitle ? ' - ' + currentTask.pullRequestTitle : ''
}`;
let message;
if (currentTaskOnSameBranch === false && branch) {
message = this.renderMessage(
'component_navigation.status.failed_branch',
undefined,
branch
);
} else {
message = this.renderMessage('component_navigation.status.failed');
}

return (
<NavBarNotif className="alert alert-danger">
{this.renderMessage('component_navigation.status.failed')}
</NavBarNotif>
);
return <NavBarNotif className="alert alert-danger">{message}</NavBarNotif>;
}
return null;
}

+ 19
- 0
server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx Zobrazit soubor

@@ -43,6 +43,25 @@ it('renders background task error correctly', () => {
expect(getWrapper()).toMatchSnapshot();
});

it('renders background task error correctly for a different branch/PR', () => {
expect(
getWrapper({
currentTask: { branch: 'my/branch', status: 'FAILED' } as Task,
currentTaskOnSameBranch: false
})
).toMatchSnapshot();
expect(
getWrapper({
currentTask: {
pullRequest: '650',
pullRequestTitle: 'feature/my_pr',
status: 'FAILED'
} as Task,
currentTaskOnSameBranch: false
})
).toMatchSnapshot();
});

it('renders background task pending info correctly', () => {
expect(getWrapper({ isPending: true })).toMatchSnapshot();
});

+ 65
- 9
server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBgTaskNotif-test.tsx.snap Zobrazit soubor

@@ -4,9 +4,50 @@ exports[`renders background task error correctly 1`] = `
<NavBarNotif
className="alert alert-danger"
>
<span>
component_navigation.status.failed
</span>
<FormattedMessage
defaultMessage="component_navigation.status.failed"
id="component_navigation.status.failed"
values={
Object {
"branch": undefined,
"url": undefined,
}
}
/>
</NavBarNotif>
`;

exports[`renders background task error correctly for a different branch/PR 1`] = `
<NavBarNotif
className="alert alert-danger"
>
<FormattedMessage
defaultMessage="component_navigation.status.failed_branch"
id="component_navigation.status.failed_branch"
values={
Object {
"branch": "my/branch",
"url": undefined,
}
}
/>
</NavBarNotif>
`;

exports[`renders background task error correctly for a different branch/PR 2`] = `
<NavBarNotif
className="alert alert-danger"
>
<FormattedMessage
defaultMessage="component_navigation.status.failed_branch"
id="component_navigation.status.failed_branch"
values={
Object {
"branch": "650 - feature/my_pr",
"url": undefined,
}
}
/>
</NavBarNotif>
`;

@@ -17,9 +58,16 @@ exports[`renders background task in progress info correctly 1`] = `
<i
className="spinner spacer-right text-bottom"
/>
<span>
component_navigation.status.in_progress
</span>
<FormattedMessage
defaultMessage="component_navigation.status.in_progress"
id="component_navigation.status.in_progress"
values={
Object {
"branch": undefined,
"url": undefined,
}
}
/>
</NavBarNotif>
`;

@@ -42,9 +90,16 @@ exports[`renders background task pending info correctly 1`] = `
<PendingIcon
className="spacer-right"
/>
<span>
component_navigation.status.pending
</span>
<FormattedMessage
defaultMessage="component_navigation.status.pending"
id="component_navigation.status.pending"
values={
Object {
"branch": undefined,
"url": undefined,
}
}
/>
</NavBarNotif>
`;

@@ -60,6 +115,7 @@ exports[`renders background task pending info correctly for admin 1`] = `
id="component_navigation.status.pending.admin"
values={
Object {
"branch": undefined,
"url": <Link
onlyActiveOnIndex={false}
style={Object {}}

+ 2
- 0
sonar-core/src/main/resources/org/sonar/l10n/core.properties Zobrazit soubor

@@ -2257,6 +2257,8 @@ marketplace.search=Search by features, tags, or categories...
#------------------------------------------------------------------------------
component_navigation.status.failed=The last analysis has failed.
component_navigation.status.failed.admin=The last analysis has failed. More details available on the {url} page.
component_navigation.status.failed_branch=The last analysis on this project ({branch}) failed.
component_navigation.status.failed_branch.admin=The last analysis on this project ({branch}) failed. More details available on the {url} page.
component_navigation.status.pending=There is a pending analysis.
component_navigation.status.pending.admin=There is a pending analysis. More details available on the {url} page.
component_navigation.status.in_progress=The analysis is in progress.

Načítá se…
Zrušit
Uložit