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 = () => (
<div className="boxed-group-inner">
<div className="flex-columns">
</div>
<div className="big-spacer-bottom">
- {buildTool === BuildTools.Maven && <PipeCommandMaven />}
- {buildTool === BuildTools.Gradle && <PipeCommandGradle />}
- {buildTool === BuildTools.Other && <PipeCommandOther />}
+ <PipeCommand buildTool={buildTool} branchesEnabled={branchesEnabled} />
</div>
<p className="little-spacer-bottom">
- {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')}
</p>
<p className="huge-spacer-bottom">
/>
);
}
+
+export default withAppState(YmlFileStep);
*/
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();
);
function shallowRender(props: Partial<YmlFileStepProps> = {}) {
- return shallow<YmlFileStepProps>(<YmlFileStep open={true} {...props} />);
+ return shallow<YmlFileStepProps>(
+ <YmlFileStep appState={mockAppState({ branchesEnabled: true })} open={true} {...props} />
+ );
}
onOpen={[Function]}
open={false}
/>
- <YmlFileStep
+ <Connect(withAppState(YmlFileStep))
open={false}
/>
</Fragment>
<div
className="big-spacer-bottom"
>
- <PipeCommandGradle />
+ <PipeCommand
+ branchesEnabled={true}
+ buildTool="gradle"
+ />
</div>
<p
className="little-spacer-bottom"
<div
className="big-spacer-bottom"
>
- <PipeCommandMaven />
+ <PipeCommand
+ branchesEnabled={true}
+ buildTool="maven"
+ />
</div>
<p
className="little-spacer-bottom"
<div
className="big-spacer-bottom"
>
- <PipeCommandOther />
+ <PipeCommand
+ branchesEnabled={true}
+ buildTool="other"
+ />
</div>
<p
className="little-spacer-bottom"
--- /dev/null
+/*
+ * 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';
+import { BuildTools } from '../types';
+
+export interface PipeCommandProps {
+ branchesEnabled?: boolean;
+ buildTool: BuildTools;
+}
+
+const BUILD_TOOL_SPECIFIC = {
+ [BuildTools.Gradle]: { image: 'gradle:jre11-slim', script: 'gradle sonarqube' },
+ [BuildTools.Maven]: {
+ image: 'maven:3.6.3-jdk-11',
+ script: `
+ - mvn verify sonar:sonar`
+ },
+ [BuildTools.Other]: {
+ image: `
+ name: sonarsource/sonar-scanner-cli:latest
+ entrypoint: [""]`,
+ script: `
+ - sonar-scanner`
+ }
+};
+
+export default function PipeCommand({ branchesEnabled, buildTool }: PipeCommandProps) {
+ const onlyBlock = branchesEnabled
+ ? `- merge_requests
+ - master
+ - develop`
+ : '- master # or the name of your main branch';
+
+ const { image, script } = BUILD_TOOL_SPECIFIC[buildTool];
+
+ const command = `sonarqube-check:
+ image: ${image}
+ 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: ${script}
+ allow_failure: true
+ only:
+ ${onlyBlock}
+`;
+
+ return <CodeSnippet snippet={command} />;
+}
+++ /dev/null
-/*
- * 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 <CodeSnippet snippet={command} />;
-}
+++ /dev/null
-/*
- * 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 <CodeSnippet snippet={command} />;
-}
+++ /dev/null
-/*
- * 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 PipeCommandOther() {
- const command = `sonarqube-check:
- image:
- name: sonarsource/sonar-scanner-cli:latest
- entrypoint: [""]
- 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:
- - sonar-scanner
- allow_failure: true
- only:
- - merge_requests
- - master
- - develop
-`;
-
- return <CodeSnippet snippet={command} />;
-}
--- /dev/null
+/*
+ * 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 { BuildTools } from '../../types';
+import PipeCommand from '../PipeCommand';
+
+it.each([[BuildTools.Gradle], [BuildTools.Maven], [BuildTools.Other]])(
+ 'should render correctly for %s',
+ buildTool => {
+ expect(shallow(<PipeCommand buildTool={buildTool} branchesEnabled={true} />)).toMatchSnapshot(
+ 'branches enabled'
+ );
+ expect(shallow(<PipeCommand buildTool={buildTool} branchesEnabled={true} />)).toMatchSnapshot(
+ 'branches not enabled'
+ );
+ }
+);
+++ /dev/null
-/*
- * 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(<PipeCommandGradle />)).toMatchSnapshot();
-});
+++ /dev/null
-/*
- * 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(<PipeCommandMaven />)).toMatchSnapshot();
-});
+++ /dev/null
-/*
- * 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 PipeCommandOther from '../PipeCommandOther';
-
-it('should render correctly', () => {
- expect(shallow(<PipeCommandOther />)).toMatchSnapshot();
-});
--- /dev/null
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly for gradle: branches enabled 1`] = `
+<CodeSnippet
+ snippet="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
+"
+/>
+`;
+
+exports[`should render correctly for gradle: branches not enabled 1`] = `
+<CodeSnippet
+ snippet="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
+"
+/>
+`;
+
+exports[`should render correctly for maven: branches enabled 1`] = `
+<CodeSnippet
+ snippet="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
+"
+/>
+`;
+
+exports[`should render correctly for maven: branches not enabled 1`] = `
+<CodeSnippet
+ snippet="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
+"
+/>
+`;
+
+exports[`should render correctly for other: branches enabled 1`] = `
+<CodeSnippet
+ snippet="sonarqube-check:
+ image:
+ name: sonarsource/sonar-scanner-cli:latest
+ entrypoint: [\\"\\"]
+ 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:
+ - sonar-scanner
+ allow_failure: true
+ only:
+ - merge_requests
+ - master
+ - develop
+"
+/>
+`;
+
+exports[`should render correctly for other: branches not enabled 1`] = `
+<CodeSnippet
+ snippet="sonarqube-check:
+ image:
+ name: sonarsource/sonar-scanner-cli:latest
+ entrypoint: [\\"\\"]
+ 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:
+ - sonar-scanner
+ allow_failure: true
+ only:
+ - merge_requests
+ - master
+ - develop
+"
+/>
+`;
+++ /dev/null
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`should render correctly 1`] = `
-<CodeSnippet
- snippet="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
-"
-/>
-`;
+++ /dev/null
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`should render correctly 1`] = `
-<CodeSnippet
- snippet="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
-"
-/>
-`;
+++ /dev/null
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`should render correctly 1`] = `
-<CodeSnippet
- snippet="sonarqube-check:
- image:
- name: sonarsource/sonar-scanner-cli:latest
- entrypoint: [\\"\\"]
- 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:
- - sonar-scanner
- allow_failure: true
- only:
- - merge_requests
- - master
- - develop
-"
-/>
-`;
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}.