]> source.dussan.org Git - sonarqube.git/blob
937b57e8e71a72124adf0ea23326d1cc51f81095
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2023 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 3 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20 import * as React from 'react';
21 import { translate } from '../../../helpers/l10n';
22 import {
23   AlmKeys,
24   AlmSettingsInstance,
25   ProjectAlmBindingResponse,
26 } from '../../../types/alm-settings';
27 import { Component } from '../../../types/types';
28 import { LoggedInUser } from '../../../types/users';
29 import AllSetStep from '../components/AllSetStep';
30 import FinishButton from '../components/FinishButton';
31 import GithubCFamilyExampleRepositories from '../components/GithubCFamilyExampleRepositories';
32 import Step from '../components/Step';
33 import YamlFileStep from '../components/YamlFileStep';
34 import { BuildTools, TutorialModes } from '../types';
35 import AnalysisCommand from './AnalysisCommand';
36 import RepositoryVariables from './RepositoryVariables';
37
38 export enum Steps {
39   REPOSITORY_VARIABLES = 1,
40   YAML = 2,
41   ALL_SET = 3,
42 }
43
44 export interface BitbucketPipelinesTutorialProps {
45   almBinding?: AlmSettingsInstance;
46   baseUrl: string;
47   component: Component;
48   currentUser: LoggedInUser;
49   mainBranchName: string;
50   projectBinding?: ProjectAlmBindingResponse;
51   willRefreshAutomatically?: boolean;
52 }
53
54 export default function BitbucketPipelinesTutorial(props: BitbucketPipelinesTutorialProps) {
55   const {
56     almBinding,
57     baseUrl,
58     currentUser,
59     component,
60     projectBinding,
61     willRefreshAutomatically,
62     mainBranchName,
63   } = props;
64
65   const [step, setStep] = React.useState<Steps>(Steps.REPOSITORY_VARIABLES);
66   return (
67     <>
68       <Step
69         finished={step > Steps.REPOSITORY_VARIABLES}
70         onOpen={() => setStep(Steps.REPOSITORY_VARIABLES)}
71         open={step === Steps.REPOSITORY_VARIABLES}
72         renderForm={() => (
73           <RepositoryVariables
74             almBinding={almBinding}
75             baseUrl={baseUrl}
76             component={component}
77             currentUser={currentUser}
78             onDone={() => setStep(Steps.YAML)}
79             projectBinding={projectBinding}
80           />
81         )}
82         stepNumber={Steps.REPOSITORY_VARIABLES}
83         stepTitle={translate('onboarding.tutorial.with.bitbucket_pipelines.create_secret.title')}
84       />
85       <Step
86         finished={step > Steps.YAML}
87         onOpen={() => setStep(Steps.YAML)}
88         open={step === Steps.YAML}
89         renderForm={() => (
90           <YamlFileStep>
91             {(buildTool) => (
92               <>
93                 {buildTool === BuildTools.CFamily && (
94                   <GithubCFamilyExampleRepositories
95                     className="big-spacer-top"
96                     ci={TutorialModes.BitbucketPipelines}
97                   />
98                 )}
99                 <AnalysisCommand
100                   buildTool={buildTool}
101                   component={component}
102                   mainBranchName={mainBranchName}
103                 />
104                 <FinishButton onClick={() => setStep(Steps.ALL_SET)} />
105               </>
106             )}
107           </YamlFileStep>
108         )}
109         stepNumber={Steps.YAML}
110         stepTitle={translate('onboarding.tutorial.with.bitbucket_pipelines.yaml.title')}
111       />
112       <AllSetStep
113         alm={almBinding?.alm || AlmKeys.BitbucketCloud}
114         open={step === Steps.ALL_SET}
115         stepNumber={Steps.ALL_SET}
116         willRefreshAutomatically={willRefreshAutomatically}
117       />
118     </>
119   );
120 }