From 181461fd642c1d1505ce90465cba46ce5b221425 Mon Sep 17 00:00:00 2001 From: Philippe Perrin Date: Fri, 12 Nov 2021 12:38:32 +0100 Subject: [PATCH] SONAR-15086 Link C/C++ sample projects to tutorial --- .../azure-pipelines/commands/ClangGCC.tsx | 8 +- .../__snapshots__/ClangGCC-test.tsx.snap | 15 ++ .../BitbucketPipelinesTutorial.tsx | 8 ++ .../GithubCFamilyExampleRepositories.css | 23 ++++ .../GithubCFamilyExampleRepositories.tsx | 81 +++++++++++ .../tutorials/components/YamlFileStep.tsx | 35 ++--- .../GithubCFamilyExampleRepositories-test.tsx | 37 +++++ ...ubCFamilyExampleRepositories-test.tsx.snap | 61 +++++++++ .../__snapshots__/YamlFileStep-test.tsx.snap | 128 +++++++++--------- .../github-action/commands/CFamily.tsx | 12 +- .../__snapshots__/CFamily-test.tsx.snap | 31 ++++- .../tutorials/gitlabci/YmlFileStep.tsx | 12 +- .../__snapshots__/YmlFileStep-test.tsx.snap | 8 ++ .../jenkins/buildtool-steps/CFamilly.tsx | 12 +- .../__snapshots__/CFamilly-test.tsx.snap | 31 ++++- .../tutorials/manual/BuildToolForm.tsx | 11 +- .../tutorials/manual/ProjectAnalysisStep.tsx | 2 +- .../resources/org/sonar/l10n/core.properties | 1 + 18 files changed, 411 insertions(+), 105 deletions(-) create mode 100644 server/sonar-web/src/main/js/components/tutorials/components/GithubCFamilyExampleRepositories.css create mode 100644 server/sonar-web/src/main/js/components/tutorials/components/GithubCFamilyExampleRepositories.tsx create mode 100644 server/sonar-web/src/main/js/components/tutorials/components/__tests__/GithubCFamilyExampleRepositories-test.tsx create mode 100644 server/sonar-web/src/main/js/components/tutorials/components/__tests__/__snapshots__/GithubCFamilyExampleRepositories-test.tsx.snap diff --git a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/ClangGCC.tsx b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/ClangGCC.tsx index 3fd4df99852..0305a91df0a 100644 --- a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/ClangGCC.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/ClangGCC.tsx @@ -23,9 +23,10 @@ import { translate } from '../../../../helpers/l10n'; import { getHostUrl } from '../../../../helpers/urls'; import CodeSnippet from '../../../common/CodeSnippet'; import { CompilationInfo } from '../../components/CompilationInfo'; +import GithubCFamilyExampleRepositories from '../../components/GithubCFamilyExampleRepositories'; import RenderOptions from '../../components/RenderOptions'; import SentenceWithHighlights from '../../components/SentenceWithHighlights'; -import { BuildTools, OSs } from '../../types'; +import { BuildTools, OSs, TutorialModes } from '../../types'; import AlertClassicEditor from './AlertClassicEditor'; import PrepareAnalysisCommand, { PrepareType } from './PrepareAnalysisCommand'; import PublishSteps from './PublishSteps'; @@ -102,6 +103,11 @@ unzip build-wrapper.zip`, {os && ( <> +
  1. diff --git a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/__tests__/__snapshots__/ClangGCC-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/__tests__/__snapshots__/ClangGCC-test.tsx.snap index 88c2a0fd284..53c9be6755f 100644 --- a/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/__tests__/__snapshots__/ClangGCC-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/azure-pipelines/commands/__tests__/__snapshots__/ClangGCC-test.tsx.snap @@ -20,6 +20,11 @@ exports[`should render correctly for "linux" 1`] = ` ] } /> +
      +
        +
          {buildTool => ( <> + {buildTool === BuildTools.CFamily && ( + + )} setStep(Steps.ALL_SET)} /> diff --git a/server/sonar-web/src/main/js/components/tutorials/components/GithubCFamilyExampleRepositories.css b/server/sonar-web/src/main/js/components/tutorials/components/GithubCFamilyExampleRepositories.css new file mode 100644 index 00000000000..5ea4710f974 --- /dev/null +++ b/server/sonar-web/src/main/js/components/tutorials/components/GithubCFamilyExampleRepositories.css @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 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. + */ + +.github-cfamily-example-repositories-box { + box-sizing: border-box; +} diff --git a/server/sonar-web/src/main/js/components/tutorials/components/GithubCFamilyExampleRepositories.tsx b/server/sonar-web/src/main/js/components/tutorials/components/GithubCFamilyExampleRepositories.tsx new file mode 100644 index 00000000000..3d06339038c --- /dev/null +++ b/server/sonar-web/src/main/js/components/tutorials/components/GithubCFamilyExampleRepositories.tsx @@ -0,0 +1,81 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 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 classNames from 'classnames'; +import React from 'react'; +import { translate } from '../../../helpers/l10n'; +import { getBaseUrl } from '../../../helpers/system'; +import { OSs, TutorialModes } from '../types'; +import './GithubCFamilyExampleRepositories.css'; + +export interface GithubCFamilyExampleRepositoriesProps { + className?: string; + os?: OSs; + ci?: TutorialModes; +} + +const OS_SEARCH_MAP = { + [OSs.Linux]: 'linux', + [OSs.Windows]: 'windows', + [OSs.MacOS]: 'macos' +}; + +const CI_SEARCH_MAP = { + [TutorialModes.Jenkins]: 'jenkins', + [TutorialModes.AzurePipelines]: 'azure', + [TutorialModes.GitHubActions]: 'gh-actions', + [TutorialModes.GitLabCI]: 'gitlab', + [TutorialModes.BitbucketPipelines]: 'bitbucket', + [TutorialModes.Manual]: 'manual', + [TutorialModes.OtherCI]: 'manual' +}; + +export default function GithubCFamilyExampleRepositories( + props: GithubCFamilyExampleRepositoriesProps +) { + const { className, os, ci } = props; + const queryParams = ['sq', os ? OS_SEARCH_MAP[os] : undefined, ci ? CI_SEARCH_MAP[ci] : undefined] + .filter(s => !!s) + .join('+'); + const link = `https://github.com/orgs/sonarsource-cfamily-examples/repositories?q=${queryParams}`; + + return ( +
          + +

          + {translate('onboarding.tutorial.cfamily.examples_repositories_description')} +

          +
          + ); +} diff --git a/server/sonar-web/src/main/js/components/tutorials/components/YamlFileStep.tsx b/server/sonar-web/src/main/js/components/tutorials/components/YamlFileStep.tsx index e8bbc19a1b5..28a6ff96afd 100644 --- a/server/sonar-web/src/main/js/components/tutorials/components/YamlFileStep.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/components/YamlFileStep.tsx @@ -28,12 +28,6 @@ export interface YamlFileStepProps { hasCLanguageFeature: boolean; } -export interface AnalysisCommandProps { - appState: T.AppState; - buildTool?: BuildTools; - component: T.Component; -} - export function YamlFileStep(props: YamlFileStepProps) { const { children, hasCLanguageFeature } = props; @@ -46,22 +40,19 @@ export function YamlFileStep(props: YamlFileStepProps) { const [buildToolSelected, setBuildToolSelected] = React.useState(); return ( - <> -
            -
          1. - {translate('onboarding.build')} - - setBuildToolSelected(value as BuildTools)} - options={buildTools} - optionLabelKey="onboarding.build" - /> -
          2. - {children && buildToolSelected && children(buildToolSelected)} -
          - +
            +
          1. + {translate('onboarding.build')} + setBuildToolSelected(value as BuildTools)} + options={buildTools} + optionLabelKey="onboarding.build" + /> +
          2. + {children && buildToolSelected && children(buildToolSelected)} +
          ); } diff --git a/server/sonar-web/src/main/js/components/tutorials/components/__tests__/GithubCFamilyExampleRepositories-test.tsx b/server/sonar-web/src/main/js/components/tutorials/components/__tests__/GithubCFamilyExampleRepositories-test.tsx new file mode 100644 index 00000000000..8f1d5b082f6 --- /dev/null +++ b/server/sonar-web/src/main/js/components/tutorials/components/__tests__/GithubCFamilyExampleRepositories-test.tsx @@ -0,0 +1,37 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 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 { shallow } from 'enzyme'; +import * as React from 'react'; +import { OSs, TutorialModes } from '../../types'; +import GithubCFamilyExampleRepositories, { + GithubCFamilyExampleRepositoriesProps +} from '../GithubCFamilyExampleRepositories'; + +it('should render correctly', () => { + expect(shallowRender()).toMatchSnapshot(); + expect(shallowRender({ os: OSs.MacOS, ci: TutorialModes.AzurePipelines })).toMatchSnapshot(); +}); + +function shallowRender(props: Partial = {}) { + return shallow( + + ); +} diff --git a/server/sonar-web/src/main/js/components/tutorials/components/__tests__/__snapshots__/GithubCFamilyExampleRepositories-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/components/__tests__/__snapshots__/GithubCFamilyExampleRepositories-test.tsx.snap new file mode 100644 index 00000000000..15c783d362b --- /dev/null +++ b/server/sonar-web/src/main/js/components/tutorials/components/__tests__/__snapshots__/GithubCFamilyExampleRepositories-test.tsx.snap @@ -0,0 +1,61 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly 1`] = ` +
          + +

          + onboarding.tutorial.cfamily.examples_repositories_description +

          +
          +`; + +exports[`should render correctly 2`] = ` +
          + +

          + onboarding.tutorial.cfamily.examples_repositories_description +

          +
          +`; diff --git a/server/sonar-web/src/main/js/components/tutorials/components/__tests__/__snapshots__/YamlFileStep-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/components/__tests__/__snapshots__/YamlFileStep-test.tsx.snap index 5b13369d15c..3f8c491c253 100644 --- a/server/sonar-web/src/main/js/components/tutorials/components/__tests__/__snapshots__/YamlFileStep-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/components/__tests__/__snapshots__/YamlFileStep-test.tsx.snap @@ -1,77 +1,77 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`should render child correctly: C unavailable 1`] = ` - -
            +
          1. -
          2. - onboarding.build - -
          3. -
          -
          + onboarding.build + + +
        `; exports[`should render correctly: C available 1`] = ` - -
          +
        1. -
        2. - onboarding.build - -
        3. -
        -
        + onboarding.build + + +
      `; exports[`should render correctly: C unavailable 1`] = ` - -
        +
      1. -
      2. - onboarding.build - -
      3. -
      -
      + onboarding.build + + +
    `; diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/CFamily.tsx b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/CFamily.tsx index 552067f30e0..987115d5339 100644 --- a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/CFamily.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/CFamily.tsx @@ -23,8 +23,9 @@ import { CompilationInfo } from '../../components/CompilationInfo'; import CreateYmlFile from '../../components/CreateYmlFile'; import DefaultProjectKey from '../../components/DefaultProjectKey'; import FinishButton from '../../components/FinishButton'; +import GithubCFamilyExampleRepositories from '../../components/GithubCFamilyExampleRepositories'; import RenderOptions from '../../components/RenderOptions'; -import { OSs } from '../../types'; +import { OSs, TutorialModes } from '../../types'; export interface CFamilyProps { branchesEnabled?: boolean; @@ -147,7 +148,7 @@ export default function CFamily(props: CFamilyProps) { return ( <> -
  2. +
  3. {translate('onboarding.build.other.os')} + {os && ( + + )}
  4. {os && ( <> diff --git a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/__tests__/__snapshots__/CFamily-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/__tests__/__snapshots__/CFamily-test.tsx.snap index 112dd555078..8db7aead827 100644 --- a/server/sonar-web/src/main/js/components/tutorials/github-action/commands/__tests__/__snapshots__/CFamily-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/github-action/commands/__tests__/__snapshots__/CFamily-test.tsx.snap @@ -26,7 +26,9 @@ exports[`should render correctly 1`] = ` } } /> -
  5. +
  6. onboarding.build.other.os @@ -72,7 +74,9 @@ exports[`should render correctly for linux: branches disabled 1`] = ` } } /> -
  7. +
  8. onboarding.build.other.os @@ -89,6 +93,11 @@ exports[`should render correctly for linux: branches disabled 1`] = ` ] } /> +
  9. -
  10. +
  11. onboarding.build.other.os @@ -185,6 +196,11 @@ exports[`should render correctly for mac: branches enabled 1`] = ` ] } /> +
  12. -
  13. +
  14. onboarding.build.other.os @@ -280,6 +298,11 @@ exports[`should render correctly for win: branches enabled 1`] = ` ] } /> +
  15. {buildTool && ( <> + {buildTool === BuildTools.CFamily && ( + + )}
    -
    -

    {branchesEnabled ? translate('onboarding.tutorial.with.gitlab_ci.yml.baseconfig') : translate('onboarding.tutorial.with.gitlab_ci.yml.baseconfig.no_branches')}

    -

    {translate('onboarding.tutorial.with.gitlab_ci.yml.existing')}

    )} diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/YmlFileStep-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/YmlFileStep-test.tsx.snap index c7616079835..7ac6df811c5 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/YmlFileStep-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/YmlFileStep-test.tsx.snap @@ -11,6 +11,10 @@ exports[`should render correctly for build tool cfamily: with branch support 1`] className="flex-column-full" > +
    @@ -71,6 +75,10 @@ exports[`should render correctly for build tool cfamily: without branch support className="flex-column-full" > +
    diff --git a/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/CFamilly.tsx b/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/CFamilly.tsx index ad394741e29..1860f04a149 100644 --- a/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/CFamilly.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/CFamilly.tsx @@ -22,8 +22,9 @@ import { translate } from '../../../../helpers/l10n'; import { CompilationInfo } from '../../components/CompilationInfo'; import DefaultProjectKey from '../../components/DefaultProjectKey'; import FinishButton from '../../components/FinishButton'; +import GithubCFamilyExampleRepositories from '../../components/GithubCFamilyExampleRepositories'; import RenderOptions from '../../components/RenderOptions'; -import { OSs } from '../../types'; +import { OSs, TutorialModes } from '../../types'; import { LanguageProps } from '../JenkinsfileStep'; import CreateJenkinsfileBulletPoint from './CreateJenkinsfileBulletPoint'; @@ -107,7 +108,7 @@ export default function CFamilly(props: LanguageProps) { return ( <> -
  16. +
  17. {translate('onboarding.build.other.os')} setOs(value as OSs)} options={Object.values(OSs)} /> + {os && ( + + )}
  18. {os && ( <> diff --git a/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/__tests__/__snapshots__/CFamilly-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/__tests__/__snapshots__/CFamilly-test.tsx.snap index 8cd9fedca98..3a258621fc0 100644 --- a/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/__tests__/__snapshots__/CFamilly-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/jenkins/buildtool-steps/__tests__/__snapshots__/CFamilly-test.tsx.snap @@ -26,7 +26,9 @@ exports[`should render correctly for 1`] = ` } } /> -
  19. +
  20. onboarding.build.other.os -
  21. +
  22. onboarding.build.other.os +
  23. -
  24. +
  25. onboarding.build.other.os +
  26. -
  27. +
  28. onboarding.build.other.os +
  29. { titleLabelKey="onboarding.build.other.os" /> )} + + {config.buildTool === BuildTools.CFamily && config.os && ( + + )} ); } diff --git a/server/sonar-web/src/main/js/components/tutorials/manual/ProjectAnalysisStep.tsx b/server/sonar-web/src/main/js/components/tutorials/manual/ProjectAnalysisStep.tsx index d5e9334567f..285cbea5683 100644 --- a/server/sonar-web/src/main/js/components/tutorials/manual/ProjectAnalysisStep.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/manual/ProjectAnalysisStep.tsx @@ -54,7 +54,7 @@ export default class ProjectAnalysisStep extends React.PureComponent {this.state.config && ( -
    +