import OrganizationAvatar from '../../../../components/common/OrganizationAvatar';
import OrganizationHelmet from '../../../../components/common/OrganizationHelmet';
import OrganizationLink from '../../../../components/ui/OrganizationLink';
+import { sanitizeAlmId } from '../../../../helpers/almIntegrations';
import { collapsePath, limitComponentName } from '../../../../helpers/path';
-import { getProjectUrl } from '../../../../helpers/urls';
+import { getProjectUrl, getBaseUrl } from '../../../../helpers/urls';
+import { isSonarCloud } from '../../../../helpers/system';
interface StateProps {
organization?: Organization;
</>
)}
{renderBreadcrumbs(component.breadcrumbs)}
+ {isSonarCloud() &&
+ component.almRepoUrl && (
+ <a
+ className="link-no-underline"
+ href={component.almRepoUrl}
+ rel="noopener noreferrer"
+ target="_blank">
+ <img
+ alt={sanitizeAlmId(component.almId)}
+ className="text-text-top spacer-left"
+ height={16}
+ src={`${getBaseUrl()}/images/sonarcloud/${sanitizeAlmId(component.almId)}.svg`}
+ width={16}
+ />
+ </a>
+ )}
{props.currentBranchLike && (
<ComponentNavBranch
branchLikes={props.branchLikes}
import { shallow } from 'enzyme';
import { ComponentNavHeader } from '../ComponentNavHeader';
import { Visibility } from '../../../../types';
+import { isSonarCloud } from '../../../../../helpers/system';
+
+jest.mock('../../../../../helpers/system', () => ({
+ isSonarCloud: jest.fn().mockReturnValue(false)
+}));
+
+const component = {
+ breadcrumbs: [{ key: 'my-project', name: 'My Project', qualifier: 'TRK' }],
+ key: 'my-project',
+ name: 'My Project',
+ organization: 'foo',
+ qualifier: 'TRK',
+ visibility: Visibility.Public
+};
+
+const organization = {
+ key: 'foo',
+ name: 'The Foo Organization',
+ projectVisibility: Visibility.Public
+};
it('should not render breadcrumbs with one element', () => {
- const component = {
- breadcrumbs: [{ key: 'my-project', name: 'My Project', qualifier: 'TRK' }],
- key: 'my-project',
- name: 'My Project',
- organization: 'org',
- qualifier: 'TRK',
- visibility: Visibility.Public
- };
- const result = shallow(
- <ComponentNavHeader
- branchLikes={[]}
- component={component}
- currentBranchLike={undefined}
- shouldOrganizationBeDisplayed={false}
- />
- );
- expect(result).toMatchSnapshot();
+ expect(
+ shallow(
+ <ComponentNavHeader
+ branchLikes={[]}
+ component={component}
+ currentBranchLike={undefined}
+ shouldOrganizationBeDisplayed={false}
+ />
+ )
+ ).toMatchSnapshot();
});
it('should render organization', () => {
- const component = {
- breadcrumbs: [{ key: 'my-project', name: 'My Project', qualifier: 'TRK' }],
- key: 'my-project',
- name: 'My Project',
- organization: 'foo',
- qualifier: 'TRK',
- visibility: Visibility.Public
- };
- const organization = {
- key: 'foo',
- name: 'The Foo Organization',
- projectVisibility: Visibility.Public
- };
- const result = shallow(
- <ComponentNavHeader
- branchLikes={[]}
- component={component}
- currentBranchLike={undefined}
- organization={organization}
- shouldOrganizationBeDisplayed={true}
- />
- );
- expect(result).toMatchSnapshot();
+ expect(
+ shallow(
+ <ComponentNavHeader
+ branchLikes={[]}
+ component={component}
+ currentBranchLike={undefined}
+ organization={organization}
+ shouldOrganizationBeDisplayed={true}
+ />
+ )
+ ).toMatchSnapshot();
+});
+
+it('should render alm links', () => {
+ (isSonarCloud as jest.Mock<any>).mockReturnValueOnce(true);
+ expect(
+ shallow(
+ <ComponentNavHeader
+ branchLikes={[]}
+ component={{
+ ...component,
+ almId: 'bitbucketcloud',
+ almRepoUrl: 'https://bitbucket.org/foo'
+ }}
+ currentBranchLike={undefined}
+ organization={organization}
+ shouldOrganizationBeDisplayed={true}
+ />
+ )
+ ).toMatchSnapshot();
});
</header>
`;
+exports[`should render alm links 1`] = `
+<header
+ className="navbar-context-header"
+>
+ <OrganizationHelmet
+ organization={
+ Object {
+ "key": "foo",
+ "name": "The Foo Organization",
+ "projectVisibility": "public",
+ }
+ }
+ title="My Project"
+ />
+ <React.Fragment>
+ <OrganizationAvatar
+ organization={
+ Object {
+ "key": "foo",
+ "name": "The Foo Organization",
+ "projectVisibility": "public",
+ }
+ }
+ />
+ <OrganizationLink
+ className="navbar-context-header-breadcrumb-link link-base-color link-no-underline spacer-left"
+ organization={
+ Object {
+ "key": "foo",
+ "name": "The Foo Organization",
+ "projectVisibility": "public",
+ }
+ }
+ >
+ The Foo Organization
+ </OrganizationLink>
+ <span
+ className="slash-separator"
+ />
+ </React.Fragment>
+ <React.Fragment
+ key="my-project"
+ >
+ <QualifierIcon
+ className="spacer-right"
+ qualifier="TRK"
+ />
+ <Link
+ className="navbar-context-header-breadcrumb-link link-base-color link-no-underline"
+ onlyActiveOnIndex={false}
+ style={Object {}}
+ title="My Project"
+ to={
+ Object {
+ "pathname": "/dashboard",
+ "query": Object {
+ "branch": undefined,
+ "id": "my-project",
+ },
+ }
+ }
+ >
+ My Project
+ </Link>
+ </React.Fragment>
+ <a
+ className="link-no-underline"
+ href="https://bitbucket.org/foo"
+ rel="noopener noreferrer"
+ target="_blank"
+ >
+ <img
+ alt="bitbucket"
+ className="text-text-top spacer-left"
+ height={16}
+ src="/images/sonarcloud/bitbucket.svg"
+ width={16}
+ />
+ </a>
+</header>
+`;
+
exports[`should render organization 1`] = `
<header
className="navbar-context-header"
import ProjectAnalysisStep from '../components/ProjectAnalysisStep';
import TokenStep from '../components/TokenStep';
import { Component, LoggedInUser } from '../../../app/types';
+import { isVSTS } from '../../../helpers/almIntegrations';
import { translate } from '../../../helpers/l10n';
import '../styles.css';
let stepNumber = 1;
const almId = component.almId || currentUser.externalProvider;
- const showTutorial = almId !== 'microsoft';
return (
<>
<div className="page-header big-spacer-bottom">
<AnalyzeTutorialSuggestion almId={almId} />
- {showTutorial && (
+ {!isVSTS(almId) && (
<>
<TokenStep
currentUser={currentUser}
*/
import * as React from 'react';
import { FormattedMessage } from 'react-intl';
+import { isBitbucket, isGithub, isVSTS } from '../../../helpers/almIntegrations';
import { translate } from '../../../helpers/l10n';
import { getBaseUrl } from '../../../helpers/urls';
export default function AnalyzeTutorialSuggestion({ almId }: { almId?: string }) {
- if (almId && almId.startsWith('bitbucket')) {
+ if (isBitbucket(almId)) {
return (
<div className="alert alert-info big-spacer-bottom">
<p>{translate('onboarding.project_analysis.commands_for_analysis')}</p>
/>
</div>
);
- } else if (almId === 'github') {
+ } else if (isGithub(almId)) {
return (
<div className="alert alert-info big-spacer-bottom">
<p>{translate('onboarding.project_analysis.commands_for_analysis')} </p>
/>
</div>
);
- } else if (almId === 'microsoft') {
+ } else if (isVSTS(almId)) {
return (
<p className="alert alert-info big-spacer-bottom">
<FormattedMessage
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import { isBitbucket, isGithub, isVSTS, sanitizeAlmId } from '../almIntegrations';
+
+it('#isBitbucket', () => {
+ expect(isBitbucket('bitbucket')).toBeTruthy();
+ expect(isBitbucket('bitbucketcloud')).toBeTruthy();
+ expect(isBitbucket('github')).toBeFalsy();
+});
+
+it('#isGithub', () => {
+ expect(isGithub('github')).toBeTruthy();
+ expect(isGithub('bitbucket')).toBeFalsy();
+});
+
+it('#isVSTS', () => {
+ expect(isVSTS('microsoft')).toBeTruthy();
+ expect(isVSTS('github')).toBeFalsy();
+});
+
+it('#sanitizeAlmId', () => {
+ expect(sanitizeAlmId('bitbucketcloud')).toBe('bitbucket');
+ expect(sanitizeAlmId('bitbucket')).toBe('bitbucket');
+ expect(sanitizeAlmId('github')).toBe('github');
+});
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+export function isBitbucket(almId?: string) {
+ return almId && almId.startsWith('bitbucket');
+}
+
+export function isGithub(almId?: string) {
+ return almId === 'github';
+}
+
+export function isVSTS(almId?: string) {
+ return almId === 'microsoft';
+}
+
+export function sanitizeAlmId(almId?: string) {
+ if (isBitbucket(almId)) {
+ return 'bitbucket';
+ }
+ return almId;
+}