From 17c325bc8c82ac4c856dfbc7fd7af64df163fb29 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Aubert?= Date: Tue, 31 Jul 2018 12:22:15 +0200 Subject: [PATCH] SONAR-11039 Add a link to the alm repo of the linked project --- .../nav/component/ComponentNavHeader.tsx | 20 +++- .../__tests__/ComponentNavHeader-test.tsx | 100 +++++++++++------- .../ComponentNavHeader-test.tsx.snap | 82 ++++++++++++++ .../analyzeProject/AnalyzeTutorial.tsx | 4 +- .../AnalyzeTutorialSuggestion.tsx | 7 +- .../helpers/__tests__/almIntegrations-test.ts | 42 ++++++++ .../src/main/js/helpers/almIntegrations.ts | 38 +++++++ 7 files changed, 247 insertions(+), 46 deletions(-) create mode 100644 server/sonar-web/src/main/js/helpers/__tests__/almIntegrations-test.ts create mode 100644 server/sonar-web/src/main/js/helpers/almIntegrations.ts diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavHeader.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavHeader.tsx index e01fb137866..e616861f278 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavHeader.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavHeader.tsx @@ -27,8 +27,10 @@ import { getOrganizationByKey, areThereCustomOrganizations } from '../../../../s 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; @@ -66,6 +68,22 @@ export function ComponentNavHeader(props: Props) { )} {renderBreadcrumbs(component.breadcrumbs)} + {isSonarCloud() && + component.almRepoUrl && ( + + {sanitizeAlmId(component.almId)} + + )} {props.currentBranchLike && ( ({ + 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( - - ); - expect(result).toMatchSnapshot(); + expect( + shallow( + + ) + ).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( - - ); - expect(result).toMatchSnapshot(); + expect( + shallow( + + ) + ).toMatchSnapshot(); +}); + +it('should render alm links', () => { + (isSonarCloud as jest.Mock).mockReturnValueOnce(true); + expect( + shallow( + + ) + ).toMatchSnapshot(); }); diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavHeader-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavHeader-test.tsx.snap index b8498689bda..ac4d42c30e4 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavHeader-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavHeader-test.tsx.snap @@ -35,6 +35,88 @@ exports[`should not render breadcrumbs with one element 1`] = ` `; +exports[`should render alm links 1`] = ` +
+ + + + + The Foo Organization + + + + + + + My Project + + + + bitbucket + +
+`; + exports[`should render organization 1`] = `
{ let stepNumber = 1; const almId = component.almId || currentUser.externalProvider; - const showTutorial = almId !== 'microsoft'; return ( <>
@@ -67,7 +67,7 @@ export default class AnalyzeTutorial extends React.PureComponent { - {showTutorial && ( + {!isVSTS(almId) && ( <>

{translate('onboarding.project_analysis.commands_for_analysis')}

@@ -46,7 +47,7 @@ export default function AnalyzeTutorialSuggestion({ almId }: { almId?: string }) />
); - } else if (almId === 'github') { + } else if (isGithub(almId)) { return (

{translate('onboarding.project_analysis.commands_for_analysis')}

@@ -67,7 +68,7 @@ export default function AnalyzeTutorialSuggestion({ almId }: { almId?: string }) />
); - } else if (almId === 'microsoft') { + } else if (isVSTS(almId)) { return (

{ + 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'); +}); diff --git a/server/sonar-web/src/main/js/helpers/almIntegrations.ts b/server/sonar-web/src/main/js/helpers/almIntegrations.ts new file mode 100644 index 00000000000..de03cb6d315 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/almIntegrations.ts @@ -0,0 +1,38 @@ +/* + * 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; +} -- 2.39.5