From 38069298aa720559a7630734131491a6b207948c Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Tue, 26 Jan 2021 18:42:02 +0100 Subject: [PATCH] SONAR-14353 GitlabCI tutorial for CE --- .../tutorials/gitlabci/YmlFileStep.tsx | 18 +-- .../gitlabci/__tests__/YmlFileStep-test.tsx | 7 +- .../GitLabCITutorial-test.tsx.snap | 2 +- .../__snapshots__/YmlFileStep-test.tsx.snap | 15 +- .../{PipeCommandOther.tsx => PipeCommand.tsx} | 43 ++++-- .../gitlabci/commands/PipeCommandGradle.tsx | 42 ------ .../gitlabci/commands/PipeCommandMaven.tsx | 43 ------ ...andOther-test.tsx => PipeCommand-test.tsx} | 17 ++- .../__tests__/PipeCommandGradle-test.tsx | 26 ---- .../__tests__/PipeCommandMaven-test.tsx | 26 ---- .../__snapshots__/PipeCommand-test.tsx.snap | 135 ++++++++++++++++++ .../PipeCommandGradle-test.tsx.snap | 22 --- .../PipeCommandMaven-test.tsx.snap | 23 --- .../PipeCommandOther-test.tsx.snap | 25 ---- .../resources/org/sonar/l10n/core.properties | 3 +- 15 files changed, 212 insertions(+), 235 deletions(-) rename server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/{PipeCommandOther.tsx => PipeCommand.tsx} (63%) delete mode 100644 server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommandGradle.tsx delete mode 100644 server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommandMaven.tsx rename server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/{PipeCommandOther-test.tsx => PipeCommand-test.tsx} (65%) delete mode 100644 server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandGradle-test.tsx delete mode 100644 server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandMaven-test.tsx create mode 100644 server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommand-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandGradle-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandMaven-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandOther-test.tsx.snap diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/YmlFileStep.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/YmlFileStep.tsx index 1dec8870dc1..cb4126ee72e 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/YmlFileStep.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/YmlFileStep.tsx @@ -22,18 +22,18 @@ import { FormattedMessage } from 'react-intl'; import { Link } from 'react-router'; import { ClipboardIconButton } from 'sonar-ui-common/components/controls/clipboard'; import { translate } from 'sonar-ui-common/helpers/l10n'; +import { withAppState } from '../../hoc/withAppState'; import Step from '../components/Step'; -import PipeCommandGradle from './commands/PipeCommandGradle'; -import PipeCommandMaven from './commands/PipeCommandMaven'; -import PipeCommandOther from './commands/PipeCommandOther'; +import PipeCommand from './commands/PipeCommand'; import { BuildTools } from './types'; export interface YmlFileStepProps { + appState: T.AppState; buildTool?: BuildTools; open: boolean; } -export default function YmlFileStep({ buildTool, open }: YmlFileStepProps) { +export function YmlFileStep({ appState: { branchesEnabled }, buildTool, open }: YmlFileStepProps) { const renderForm = () => (
@@ -61,13 +61,13 @@ export default function YmlFileStep({ buildTool, open }: YmlFileStepProps) {
- {buildTool === BuildTools.Maven && } - {buildTool === BuildTools.Gradle && } - {buildTool === BuildTools.Other && } +

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

@@ -134,3 +134,5 @@ export default function YmlFileStep({ buildTool, open }: YmlFileStepProps) { /> ); } + +export default withAppState(YmlFileStep); diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/YmlFileStep-test.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/YmlFileStep-test.tsx index afa0332d886..6d24ad7873e 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/YmlFileStep-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/YmlFileStep-test.tsx @@ -19,9 +19,10 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; +import { mockAppState } from '../../../../helpers/testMocks'; import { renderStepContent } from '../../jenkins/test-utils'; import { BuildTools } from '../types'; -import YmlFileStep, { YmlFileStepProps } from '../YmlFileStep'; +import { YmlFileStep, YmlFileStepProps } from '../YmlFileStep'; it('should render correctly', () => { const wrapper = shallowRender(); @@ -37,5 +38,7 @@ it.each([[BuildTools.Maven], [BuildTools.Gradle], [BuildTools.Other]])( ); function shallowRender(props: Partial = {}) { - return shallow(); + return shallow( + + ); } diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-test.tsx.snap index 2f3e5aa150a..00c4ef25f2c 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-test.tsx.snap @@ -77,7 +77,7 @@ exports[`should render correctly 1`] = ` onOpen={[Function]} open={false} /> - 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 95bf2abb6e3..2fed2d0975b 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 @@ -37,7 +37,10 @@ exports[`should render correctly for build tool gradle 1`] = `

- +

- +

- +

; diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommandGradle.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommandGradle.tsx deleted file mode 100644 index 6454875ac0f..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommandGradle.tsx +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 * as React from 'react'; -import CodeSnippet from '../../../common/CodeSnippet'; - -export default function PipeCommandGradle() { - const command = `sonarqube-check: - image: gradle:jre11-slim - variables: - SONAR_USER_HOME: "\${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache - GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task - cache: - key: "\${CI_JOB_NAME}" - paths: - - .sonar/cache - script: gradle sonarqube - allow_failure: true - only: - - merge_requests - - master - - develop -`; - - return ; -} diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommandMaven.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommandMaven.tsx deleted file mode 100644 index 875a71c4191..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommandMaven.tsx +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 * as React from 'react'; -import CodeSnippet from '../../../common/CodeSnippet'; - -export default function PipeCommandMaven() { - const command = `sonarqube-check: - image: maven:3.6.3-jdk-11 - variables: - SONAR_USER_HOME: "\${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache - GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task - cache: - key: "\${CI_JOB_NAME}" - paths: - - .sonar/cache - script: - - mvn verify sonar:sonar - allow_failure: true - only: - - merge_requests - - master - - develop -`; - - return ; -} diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandOther-test.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommand-test.tsx similarity index 65% rename from server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandOther-test.tsx rename to server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommand-test.tsx index d1ad81beb2a..8e2c9367182 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandOther-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommand-test.tsx @@ -19,8 +19,17 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import PipeCommandOther from '../PipeCommandOther'; +import { BuildTools } from '../../types'; +import PipeCommand from '../PipeCommand'; -it('should render correctly', () => { - expect(shallow()).toMatchSnapshot(); -}); +it.each([[BuildTools.Gradle], [BuildTools.Maven], [BuildTools.Other]])( + 'should render correctly for %s', + buildTool => { + expect(shallow()).toMatchSnapshot( + 'branches enabled' + ); + expect(shallow()).toMatchSnapshot( + 'branches not enabled' + ); + } +); diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandGradle-test.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandGradle-test.tsx deleted file mode 100644 index f259f1a7a0f..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandGradle-test.tsx +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 PipeCommandGradle from '../PipeCommandGradle'; - -it('should render correctly', () => { - expect(shallow()).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandMaven-test.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandMaven-test.tsx deleted file mode 100644 index 2e5c109d030..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandMaven-test.tsx +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 PipeCommandMaven from '../PipeCommandMaven'; - -it('should render correctly', () => { - expect(shallow()).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommand-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommand-test.tsx.snap new file mode 100644 index 00000000000..019eef78564 --- /dev/null +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommand-test.tsx.snap @@ -0,0 +1,135 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly for gradle: branches enabled 1`] = ` + +`; + +exports[`should render correctly for gradle: branches not enabled 1`] = ` + +`; + +exports[`should render correctly for maven: branches enabled 1`] = ` + +`; + +exports[`should render correctly for maven: branches not enabled 1`] = ` + +`; + +exports[`should render correctly for other: branches enabled 1`] = ` + +`; + +exports[`should render correctly for other: branches not enabled 1`] = ` + +`; diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandGradle-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandGradle-test.tsx.snap deleted file mode 100644 index 61f4c68d1f1..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandGradle-test.tsx.snap +++ /dev/null @@ -1,22 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` - -`; diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandMaven-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandMaven-test.tsx.snap deleted file mode 100644 index 0b843680c84..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandMaven-test.tsx.snap +++ /dev/null @@ -1,23 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` - -`; diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandOther-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandOther-test.tsx.snap deleted file mode 100644 index 74e84b88d82..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandOther-test.tsx.snap +++ /dev/null @@ -1,25 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` - -`; diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 50ef223c143..680894af399 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -3357,7 +3357,8 @@ onboarding.tutorial.with.gitlab_ci.env_variables.section2.step4=Leave the "Mask onboarding.tutorial.with.gitlab_ci.yml.title=Create or update the configuration file onboarding.tutorial.with.gitlab_ci.yml.description=Create or update your {filename} file with the following content. onboarding.tutorial.with.gitlab_ci.yml.filename=.gitlab-ci.yml -onboarding.tutorial.with.gitlab_ci.yml.baseconfig=Note that this is a minimal base configuration to run a SonarQube analysis on your master branch and merge requests. +onboarding.tutorial.with.gitlab_ci.yml.baseconfig=Note that this is a minimal base configuration to run a SonarQube analysis on your main branch and merge requests. +onboarding.tutorial.with.gitlab_ci.yml.baseconfig.no_branches=Note that this is a minimal base configuration to run a SonarQube analysis on your main branch. onboarding.tutorial.with.gitlab_ci.yml.existing=If you already have a pipeline configured and running, you might want to add the example from this step to your existing yml file. onboarding.tutorial.with.gitlab_ci.yml.done=Is it done? onboarding.tutorial.with.gitlab_ci.yml.done.description=You should see the page refresh itself in a few moments with your analysis results if the {link}. -- 2.39.5