]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14738 Make tutorial links available to project admins
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Thu, 22 Apr 2021 15:08:28 +0000 (17:08 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 23 Apr 2021 20:03:28 +0000 (20:03 +0000)
23 files changed:
server/sonar-web/src/main/js/api/alm-settings.ts
server/sonar-web/src/main/js/components/tutorials/TutorialSelection.tsx
server/sonar-web/src/main/js/components/tutorials/TutorialSelectionRenderer.tsx
server/sonar-web/src/main/js/components/tutorials/__tests__/TutorialSelection-test.tsx
server/sonar-web/src/main/js/components/tutorials/__tests__/TutorialSelectionRenderer-test.tsx
server/sonar-web/src/main/js/components/tutorials/__tests__/__snapshots__/TutorialSelectionRenderer-test.tsx.snap
server/sonar-web/src/main/js/components/tutorials/__tests__/utils-test.ts
server/sonar-web/src/main/js/components/tutorials/github-action/GitHubActionTutorial.tsx
server/sonar-web/src/main/js/components/tutorials/github-action/SecretStep.tsx
server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/GitHubActionTutorial-test.tsx
server/sonar-web/src/main/js/components/tutorials/github-action/__tests__/SecretStep-test.tsx
server/sonar-web/src/main/js/components/tutorials/jenkins/JenkinsTutorial.tsx
server/sonar-web/src/main/js/components/tutorials/jenkins/MultiBranchPipelineStep.tsx
server/sonar-web/src/main/js/components/tutorials/jenkins/WebhookStep.tsx
server/sonar-web/src/main/js/components/tutorials/jenkins/WebhookStepBitbucket.tsx
server/sonar-web/src/main/js/components/tutorials/jenkins/WebhookStepGithub.tsx
server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/MultiBranchPipelineStep-test.tsx
server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/WebhookStep-test.tsx
server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/WebhookStepBitbucket-test.tsx
server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/WebhookStepGithub-test.tsx
server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/MultiBranchPipelineStep-test.tsx.snap
server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/WebhookStep-test.tsx.snap
server/sonar-web/src/main/js/components/tutorials/utils.ts

index 9491b1809ec28d9c9b2fa37a983280463743e1c3..5f264a5f33144b4c23bfbb5c595c1f747384780c 100644 (file)
@@ -36,17 +36,15 @@ import {
 } from '../types/alm-settings';
 
 export function getAlmDefinitions(): Promise<AlmSettingsBindingDefinitions> {
-  return getAlmDefinitionsNoCatch().catch(throwGlobalError);
-}
-
-export function getAlmDefinitionsNoCatch(): Promise<AlmSettingsBindingDefinitions> {
   return getJSON('/api/alm_settings/list_definitions');
 }
 
 export function getAlmSettings(project?: string): Promise<AlmSettingsInstance[]> {
-  return getJSON('/api/alm_settings/list', { project })
-    .then(({ almSettings }) => almSettings)
-    .catch(throwGlobalError);
+  return getAlmSettingsNoCatch(project).catch(throwGlobalError);
+}
+
+export function getAlmSettingsNoCatch(project?: string): Promise<AlmSettingsInstance[]> {
+  return getJSON('/api/alm_settings/list', { project }).then(({ almSettings }) => almSettings);
 }
 
 export function validateAlmSettings(key: string): Promise<string> {
index 28d0bc67435be31826210a98609cf79e9e57f509..2598ce3a320a9785af3ba3fd15eb08d236ecfe8f 100644 (file)
@@ -20,9 +20,9 @@
 import * as React from 'react';
 import { WithRouterProps } from 'react-router';
 import { getHostUrl } from 'sonar-ui-common/helpers/urls';
-import { getAlmDefinitionsNoCatch } from '../../api/alm-settings';
+import { getAlmSettingsNoCatch } from '../../api/alm-settings';
 import { getValues } from '../../api/settings';
-import { AlmBindingDefinition, ProjectAlmBindingResponse } from '../../types/alm-settings';
+import { AlmSettingsInstance, ProjectAlmBindingResponse } from '../../types/alm-settings';
 import { SettingsKey } from '../../types/settings';
 import { withRouter } from '../hoc/withRouter';
 import TutorialSelectionRenderer from './TutorialSelectionRenderer';
@@ -35,7 +35,7 @@ interface Props extends Pick<WithRouterProps, 'router' | 'location'> {
 }
 
 interface State {
-  almBinding?: AlmBindingDefinition;
+  almBinding?: AlmSettingsInstance;
   baseUrl: string;
   forceManual: boolean;
   loading: boolean;
@@ -64,17 +64,16 @@ export class TutorialSelection extends React.PureComponent<Props, State> {
   }
 
   fetchAlmBindings = async () => {
-    const { projectBinding } = this.props;
+    const { component, projectBinding } = this.props;
 
     if (projectBinding === undefined) {
       this.setState({ forceManual: true });
     } else {
-      const almDefinitions = await getAlmDefinitionsNoCatch().catch(() => undefined);
+      const almSettings = await getAlmSettingsNoCatch(component.key).catch(() => undefined);
       if (this.mounted) {
         let almBinding;
-        if (almDefinitions !== undefined) {
-          const specificDefinitions = almDefinitions[projectBinding.alm] as AlmBindingDefinition[];
-          almBinding = specificDefinitions.find(d => d.key === projectBinding.key);
+        if (almSettings !== undefined) {
+          almBinding = almSettings.find(d => d.key === projectBinding.key);
         }
         this.setState({ almBinding, forceManual: false });
       }
index 5685484eabfea02b301a2be966fbce883994e39e..ab996323948286247067b9ca8f5287fbf1a0d9fb 100644 (file)
 import * as React from 'react';
 import { translate } from 'sonar-ui-common/helpers/l10n';
 import { getBaseUrl } from 'sonar-ui-common/helpers/urls';
-import {
-  AlmBindingDefinition,
-  AlmKeys,
-  isGithubBindingDefinition,
-  ProjectAlmBindingResponse
-} from '../../types/alm-settings';
+import { AlmKeys, AlmSettingsInstance, ProjectAlmBindingResponse } from '../../types/alm-settings';
 import AzurePipelinesTutorial from './azure-pipelines/AzurePipelinesTutorial';
 import GitHubActionTutorial from './github-action/GitHubActionTutorial';
 import GitLabCITutorial from './gitlabci/GitLabCITutorial';
@@ -34,7 +29,7 @@ import ManualTutorial from './manual/ManualTutorial';
 import { TutorialModes } from './types';
 
 export interface TutorialSelectionRendererProps {
-  almBinding?: AlmBindingDefinition;
+  almBinding?: AlmSettingsInstance;
   baseUrl: string;
   component: T.Component;
   currentUser: T.LoggedInUser;
@@ -160,17 +155,15 @@ export default function TutorialSelectionRenderer(props: TutorialSelectionRender
         <ManualTutorial component={component} currentUser={currentUser} />
       )}
 
-      {selectedTutorial === TutorialModes.GitHubActions &&
-        isGithubBindingDefinition(almBinding) &&
-        projectBinding !== undefined && (
-          <GitHubActionTutorial
-            almBinding={almBinding}
-            baseUrl={baseUrl}
-            component={component}
-            currentUser={currentUser}
-            projectBinding={projectBinding}
-          />
-        )}
+      {selectedTutorial === TutorialModes.GitHubActions && projectBinding !== undefined && (
+        <GitHubActionTutorial
+          almBinding={almBinding}
+          baseUrl={baseUrl}
+          component={component}
+          currentUser={currentUser}
+          projectBinding={projectBinding}
+        />
+      )}
 
       {selectedTutorial === TutorialModes.Jenkins && projectBinding !== undefined && (
         <JenkinsTutorial
index c2cc786bb0fd08272ea34c0b58cb740b72dd4f6c..a6f02c5e439051d1f110d64b31c5822b6bb13225 100644 (file)
@@ -21,10 +21,10 @@ import { shallow } from 'enzyme';
 import * as React from 'react';
 import { waitAndUpdate } from 'sonar-ui-common/helpers/testUtils';
 import { getHostUrl } from 'sonar-ui-common/helpers/urls';
-import { getAlmDefinitionsNoCatch } from '../../../api/alm-settings';
+import { getAlmSettingsNoCatch } from '../../../api/alm-settings';
 import { getValues } from '../../../api/settings';
 import {
-  mockBitbucketBindingDefinition,
+  mockAlmSettingsInstance,
   mockProjectBitbucketBindingResponse
 } from '../../../helpers/mocks/alm-settings';
 import {
@@ -33,7 +33,6 @@ import {
   mockLoggedInUser,
   mockRouter
 } from '../../../helpers/testMocks';
-import { AlmKeys } from '../../../types/alm-settings';
 import { SettingsKey } from '../../../types/settings';
 import { TutorialSelection } from '../TutorialSelection';
 import { TutorialModes } from '../types';
@@ -43,7 +42,7 @@ jest.mock('sonar-ui-common/helpers/urls', () => ({
 }));
 
 jest.mock('../../../api/alm-settings', () => ({
-  getAlmDefinitionsNoCatch: jest.fn().mockRejectedValue(null)
+  getAlmSettingsNoCatch: jest.fn().mockRejectedValue(null)
 }));
 
 jest.mock('../../../api/settings', () => ({
@@ -70,10 +69,11 @@ it('should not select anything if project is bound', async () => {
 
 it('should correctly find the global ALM binding definition', async () => {
   const key = 'foo';
-  const almBinding = mockBitbucketBindingDefinition({ key });
-  (getAlmDefinitionsNoCatch as jest.Mock).mockResolvedValueOnce({
-    [AlmKeys.BitbucketServer]: [almBinding]
-  });
+  const almBinding = mockAlmSettingsInstance({ key });
+  (getAlmSettingsNoCatch as jest.Mock).mockResolvedValueOnce([
+    almBinding,
+    mockAlmSettingsInstance({ key: 'bar' })
+  ]);
   const wrapper = shallowRender({ projectBinding: mockProjectBitbucketBindingResponse({ key }) });
   await waitAndUpdate(wrapper);
   expect(wrapper.state().almBinding).toBe(almBinding);
index b67a9349fc6cf30cd5e9f76bc707bd853a1a9eb6..bad6a40ffbe9bfffb22cfd36d44fed5b2cca4584 100644 (file)
@@ -21,8 +21,7 @@ import { shallow } from 'enzyme';
 import * as React from 'react';
 import { click } from 'sonar-ui-common/helpers/testUtils';
 import {
-  mockBitbucketBindingDefinition,
-  mockGithubBindingDefinition,
+  mockAlmSettingsInstance,
   mockProjectAzureBindingResponse,
   mockProjectBitbucketBindingResponse,
   mockProjectGithubBindingResponse,
@@ -57,7 +56,6 @@ it('should render correctly', () => {
   ).toMatchSnapshot('jenkins tutorial');
   expect(
     shallowRender({
-      almBinding: mockGithubBindingDefinition(),
       selectedTutorial: TutorialModes.GitHubActions,
       projectBinding: mockProjectGithubBindingResponse()
     })
@@ -141,7 +139,7 @@ it('should allow mode selection for Azure DevOps', () => {
 function shallowRender(props: Partial<TutorialSelectionRendererProps> = {}) {
   return shallow<TutorialSelectionRendererProps>(
     <TutorialSelectionRenderer
-      almBinding={mockBitbucketBindingDefinition()}
+      almBinding={mockAlmSettingsInstance()}
       baseUrl="http://localhost:9000"
       component={mockComponent()}
       currentUser={mockLoggedInUser()}
index a3b3e0f8eb873de4d2828aa003277640440fc5d1..12be561a8be449272a7d60bc898bb390cc0eb1d3 100644 (file)
@@ -303,12 +303,8 @@ exports[`should render correctly: github actions tutorial 1`] = `
   <GitHubActionTutorial
     almBinding={
       Object {
-        "appId": "123456",
-        "clientId": "client1",
-        "clientSecret": "**clientsecret**",
+        "alm": "github",
         "key": "key",
-        "privateKey": "asdf1234",
-        "url": "http://github.enterprise.com",
       }
     }
     baseUrl="http://localhost:9000"
@@ -408,9 +404,8 @@ exports[`should render correctly: jenkins tutorial 1`] = `
   <Connect(JenkinsTutorial)
     almBinding={
       Object {
+        "alm": "github",
         "key": "key",
-        "personalAccessToken": "asdf1234",
-        "url": "http://bbs.enterprise.com",
       }
     }
     component={
index f972c1322505116078ec473f1d23df19663f3341..409ae9aa6f0fe1028b55b43b2ec86067d957a231 100644 (file)
@@ -18,7 +18,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import {
-  mockGithubBindingDefinition,
+  mockAlmSettingsInstance,
   mockProjectGithubBindingResponse
 } from '../../../helpers/mocks/alm-settings';
 import { buildGithubLink, getUniqueTokenName } from '../utils';
@@ -49,21 +49,24 @@ describe('getUniqueTokenName', () => {
 });
 
 describe('buildGithubLink', () => {
+  const projectBinding = mockProjectGithubBindingResponse({ repository: 'owner/reponame' });
+
   it('should work for GitHub Enterprise', () => {
     expect(
       buildGithubLink(
-        mockGithubBindingDefinition({ url: 'https://github.company.com/api/v3' }),
-        mockProjectGithubBindingResponse({ repository: 'owner/reponame' })
+        mockAlmSettingsInstance({ url: 'https://github.company.com/api/v3' }),
+        projectBinding
       )
     ).toBe('https://github.company.com/owner/reponame');
   });
 
   it('should work for github.com', () => {
     expect(
-      buildGithubLink(
-        mockGithubBindingDefinition({ url: 'http://api.github.com/' }),
-        mockProjectGithubBindingResponse({ repository: 'owner/reponame' })
-      )
+      buildGithubLink(mockAlmSettingsInstance({ url: 'http://api.github.com/' }), projectBinding)
     ).toBe('https://github.com/owner/reponame');
   });
+
+  it('should return null if there is no url defined', () => {
+    expect(buildGithubLink(mockAlmSettingsInstance({ url: undefined }), projectBinding)).toBeNull();
+  });
 });
index 1303a4cd85da2a8d88345a4e134e9a3cd1b45327..61eded6385460f373101f0258ceda779525da980 100644 (file)
@@ -19,7 +19,7 @@
  */
 import * as React from 'react';
 import { translate } from 'sonar-ui-common/helpers/l10n';
-import { GithubBindingDefinition, ProjectAlmBindingResponse } from '../../../types/alm-settings';
+import { AlmSettingsInstance, ProjectAlmBindingResponse } from '../../../types/alm-settings';
 import Step from '../components/Step';
 import SecretStep from './SecretStep';
 import YamlFileStep from './YamlFileStep';
@@ -30,7 +30,7 @@ export enum Steps {
 }
 
 export interface GitHubActionTutorialProps {
-  almBinding?: GithubBindingDefinition;
+  almBinding?: AlmSettingsInstance;
   baseUrl: string;
   component: T.Component;
   currentUser: T.LoggedInUser;
index 60c5b27a8c09b14948309bfc10dbe320a2f8ce4c..db50249deaed85eb08d2b21e16b3a7efbe501b9a 100644 (file)
@@ -22,13 +22,13 @@ import { FormattedMessage } from 'react-intl';
 import { Button } from 'sonar-ui-common/components/controls/buttons';
 import { ClipboardIconButton } from 'sonar-ui-common/components/controls/clipboard';
 import { translate } from 'sonar-ui-common/helpers/l10n';
-import { GithubBindingDefinition, ProjectAlmBindingResponse } from '../../../types/alm-settings';
+import { AlmSettingsInstance, ProjectAlmBindingResponse } from '../../../types/alm-settings';
 import SentenceWithHighlights from '../components/SentenceWithHighlights';
 import TokenStepGenerator from '../components/TokenStepGenerator';
 import { buildGithubLink } from '../utils';
 
 export interface SecretStepProps {
-  almBinding?: GithubBindingDefinition;
+  almBinding?: AlmSettingsInstance;
   baseUrl: string;
   component: T.Component;
   currentUser: T.LoggedInUser;
index 81d6aca3767348e96781f6fec12fcf1b6ca8a222..ad77015e156acfa6c60b3a2e9874a3dc6a65887a 100644 (file)
@@ -20,7 +20,7 @@
 import { shallow } from 'enzyme';
 import * as React from 'react';
 import {
-  mockGithubBindingDefinition,
+  mockAlmSettingsInstance,
   mockProjectGithubBindingResponse
 } from '../../../../helpers/mocks/alm-settings';
 import { mockComponent, mockLoggedInUser } from '../../../../helpers/testMocks';
@@ -38,7 +38,7 @@ it('should render correctly', () => {
 function shallowRender(props: Partial<GitHubActionTutorialProps> = {}) {
   return shallow<GitHubActionTutorialProps>(
     <GitHubActionTutorial
-      almBinding={mockGithubBindingDefinition()}
+      almBinding={mockAlmSettingsInstance()}
       baseUrl="test"
       currentUser={mockLoggedInUser()}
       component={mockComponent()}
index fa9c3ecbc1989cf1d0300fb88c6a713b181998e1..a4e4ea50e374c7d444d24ad992e566c95bff5fe8 100644 (file)
@@ -20,7 +20,7 @@
 import { shallow } from 'enzyme';
 import * as React from 'react';
 import {
-  mockGithubBindingDefinition,
+  mockAlmSettingsInstance,
   mockProjectGithubBindingResponse
 } from '../../../../helpers/mocks/alm-settings';
 import { mockComponent, mockLoggedInUser } from '../../../../helpers/testMocks';
@@ -30,7 +30,7 @@ it('should render correctly', () => {
   expect(shallowRender()).toMatchSnapshot('default');
   expect(
     shallowRender({
-      almBinding: mockGithubBindingDefinition()
+      almBinding: mockAlmSettingsInstance({ url: 'http://github.enterprise.com/api/v3' })
     })
   ).toMatchSnapshot('with binding information');
 });
index 15ba4fc05baaf782d891f3d08739bd3655db06c3..3ed4d76d95098852b0de7201184e47bb4ce0e253 100644 (file)
@@ -24,7 +24,7 @@ import { translate } from 'sonar-ui-common/helpers/l10n';
 import { getAppState, getCurrentUserSetting, Store } from '../../../store/rootReducer';
 import { setCurrentUserSetting } from '../../../store/users';
 import {
-  AlmBindingDefinition,
+  AlmSettingsInstance,
   isProjectBitbucketBindingResponse,
   isProjectGitHubBindingResponse,
   isProjectGitLabBindingResponse,
@@ -37,7 +37,7 @@ import PreRequisitesStep from './PreRequisitesStep';
 import WebhookStep from './WebhookStep';
 
 export interface JenkinsTutorialProps {
-  almBinding?: AlmBindingDefinition;
+  almBinding?: AlmSettingsInstance;
   branchesEnabled: boolean;
   component: T.Component;
   projectBinding: ProjectAlmBindingResponse;
index eda16fc1a5bae2328a8863ea735b5803d3013beb..cfd44f0a57b1ba3b6ddb612b275353a83de24fce 100644 (file)
@@ -21,8 +21,7 @@ import * as React from 'react';
 import { Button } from 'sonar-ui-common/components/controls/buttons';
 import { translate } from 'sonar-ui-common/helpers/l10n';
 import {
-  AlmBindingDefinition,
-  isGithubBindingDefinition,
+  AlmSettingsInstance,
   isProjectBitbucketBindingResponse,
   isProjectGitHubBindingResponse,
   isProjectGitLabBindingResponse,
@@ -37,7 +36,7 @@ import Step from '../components/Step';
 import { buildGithubLink } from '../utils';
 
 export interface MultiBranchPipelineStepProps {
-  almBinding?: AlmBindingDefinition;
+  almBinding?: AlmSettingsInstance;
   finished: boolean;
   onDone: () => void;
   onOpen: () => void;
@@ -101,10 +100,11 @@ export default function MultiBranchPipelineStep(props: MultiBranchPipelineStepPr
                       <LabelActionPair translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.github.creds" />
                     </li>
                     <li>
-                      {isGithubBindingDefinition(almBinding) ? (
+                      {almBinding !== undefined &&
+                      buildGithubLink(almBinding, projectBinding) !== null ? (
                         <LabelValuePair
                           translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.github.repo_url"
-                          value={buildGithubLink(almBinding, projectBinding)}
+                          value={buildGithubLink(almBinding, projectBinding) as string}
                         />
                       ) : (
                         <LabelActionPair translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.github.repo_url" />
index 86d8129d9edf08aef4781999a35a9c62b2b85675..2fcb02a05d673ff1004fe127541e03435d06448d 100644 (file)
@@ -22,10 +22,8 @@ import { FormattedMessage } from 'react-intl';
 import { Button, ButtonLink } from 'sonar-ui-common/components/controls/buttons';
 import { translate } from 'sonar-ui-common/helpers/l10n';
 import {
-  AlmBindingDefinition,
   AlmKeys,
-  isBitbucketBindingDefinition,
-  isGithubBindingDefinition,
+  AlmSettingsInstance,
   ProjectAlmBindingResponse
 } from '../../../types/alm-settings';
 import Step from '../components/Step';
@@ -34,7 +32,7 @@ import WebhookStepGithub from './WebhookStepGithub';
 import WebhookStepGitLab from './WebhookStepGitLab';
 
 export interface WebhookStepProps {
-  almBinding?: AlmBindingDefinition;
+  almBinding?: AlmSettingsInstance;
   branchesEnabled: boolean;
   finished: boolean;
   onDone: () => void;
@@ -50,7 +48,7 @@ function renderAlmSpecificInstructions(props: WebhookStepProps) {
     case AlmKeys.BitbucketServer:
       return (
         <WebhookStepBitbucket
-          almBinding={isBitbucketBindingDefinition(almBinding) ? almBinding : undefined}
+          almBinding={almBinding}
           branchesEnabled={branchesEnabled}
           projectBinding={projectBinding}
         />
@@ -59,7 +57,7 @@ function renderAlmSpecificInstructions(props: WebhookStepProps) {
     case AlmKeys.GitHub:
       return (
         <WebhookStepGithub
-          almBinding={isGithubBindingDefinition(almBinding) ? almBinding : undefined}
+          almBinding={almBinding}
           branchesEnabled={branchesEnabled}
           projectBinding={projectBinding}
         />
index 51b6813312d12ef095a80978a4092781f7d40228..03ab516429e644c7b1e17b686819621853dced52 100644 (file)
@@ -21,13 +21,13 @@ import * as React from 'react';
 import { FormattedMessage } from 'react-intl';
 import { Alert } from 'sonar-ui-common/components/ui/Alert';
 import { translate } from 'sonar-ui-common/helpers/l10n';
-import { BitbucketBindingDefinition, ProjectAlmBindingResponse } from '../../../types/alm-settings';
+import { AlmSettingsInstance, ProjectAlmBindingResponse } from '../../../types/alm-settings';
 import CodeSnippet from '../../common/CodeSnippet';
 import LabelActionPair from '../components/LabelActionPair';
 import SentenceWithHighlights from '../components/SentenceWithHighlights';
 
 export interface WebhookStepBitbucketProps {
-  almBinding?: BitbucketBindingDefinition;
+  almBinding?: AlmSettingsInstance;
   branchesEnabled: boolean;
   projectBinding: ProjectAlmBindingResponse;
 }
@@ -43,6 +43,7 @@ export default function WebhookStepBitbucket(props: WebhookStepBitbucketProps) {
 
   const linkUrl =
     almBinding &&
+    almBinding.url &&
     `${almBinding.url}/plugins/servlet/webhooks/projects/${projectBinding.repository}/repos/${projectBinding.slug}/create`;
 
   return (
index 37ffc16ddb2b6ccc6a67b21d1e9e5c54a0022e67..39fafeb28acd88dd32635168490ae75e184ed2ee 100644 (file)
 import * as React from 'react';
 import { FormattedMessage } from 'react-intl';
 import { translate } from 'sonar-ui-common/helpers/l10n';
-import { GithubBindingDefinition, ProjectAlmBindingResponse } from '../../../types/alm-settings';
+import { AlmSettingsInstance, ProjectAlmBindingResponse } from '../../../types/alm-settings';
 import CodeSnippet from '../../common/CodeSnippet';
 import LabelActionPair from '../components/LabelActionPair';
 import SentenceWithHighlights from '../components/SentenceWithHighlights';
 import { buildGithubLink } from '../utils';
 
 export interface WebhookStepGithubProps {
-  almBinding?: GithubBindingDefinition;
+  almBinding?: AlmSettingsInstance;
   branchesEnabled: boolean;
   projectBinding: ProjectAlmBindingResponse;
 }
index 5be36aa33105e42be1df83f7656f48a6f7c20ba4..8b10fce9399440d9016fcb49c34cb0cbebe0d496 100644 (file)
@@ -20,6 +20,7 @@
 import { shallow } from 'enzyme';
 import * as React from 'react';
 import {
+  mockAlmSettingsInstance,
   mockProjectBitbucketBindingResponse,
   mockProjectGithubBindingResponse,
   mockProjectGitLabBindingResponse
@@ -32,7 +33,12 @@ it('should render correctly', () => {
   expect(wrapper).toMatchSnapshot('Step wrapper');
   expect(renderStepContent(wrapper)).toMatchSnapshot('content for bitbucket');
   expect(
-    renderStepContent(shallowRender({ projectBinding: mockProjectGithubBindingResponse() }))
+    renderStepContent(
+      shallowRender({
+        almBinding: mockAlmSettingsInstance({ url: 'https://api.github.com/' }),
+        projectBinding: mockProjectGithubBindingResponse()
+      })
+    )
   ).toMatchSnapshot('content for github');
   expect(
     renderStepContent(shallowRender({ projectBinding: mockProjectGitLabBindingResponse() }))
index e08fa92d0c73f3353f6e7502bcfd787a70992e77..11406ff5d150b094c377febcf150db04e3455f7c 100644 (file)
 import { shallow } from 'enzyme';
 import * as React from 'react';
 import {
-  mockAzureBindingDefinition,
-  mockBitbucketBindingDefinition,
-  mockGithubBindingDefinition,
-  mockGitlabBindingDefinition,
+  mockAlmSettingsInstance,
   mockProjectAlmBindingResponse,
   mockProjectBitbucketBindingResponse,
   mockProjectGithubBindingResponse
@@ -33,24 +30,12 @@ import { renderStepContent } from '../test-utils';
 import WebhookStep, { WebhookStepProps } from '../WebhookStep';
 
 it.each([
-  [
-    AlmKeys.Azure,
-    mockAzureBindingDefinition(),
-    mockProjectAlmBindingResponse({ alm: AlmKeys.Azure })
-  ],
-  [
-    AlmKeys.BitbucketServer,
-    mockBitbucketBindingDefinition(),
-    mockProjectBitbucketBindingResponse()
-  ],
-  [AlmKeys.GitHub, mockGithubBindingDefinition(), mockProjectGithubBindingResponse()],
-  [
-    AlmKeys.GitLab,
-    mockGitlabBindingDefinition(),
-    mockProjectAlmBindingResponse({ alm: AlmKeys.GitLab })
-  ]
-])('it should render correctly for %s', (_, almBinding, projectBinding) => {
-  const wrapper = shallowRender({ almBinding, projectBinding });
+  [AlmKeys.Azure, mockProjectAlmBindingResponse({ alm: AlmKeys.Azure })],
+  [AlmKeys.BitbucketServer, mockProjectBitbucketBindingResponse()],
+  [AlmKeys.GitHub, mockProjectGithubBindingResponse()],
+  [AlmKeys.GitLab, mockProjectAlmBindingResponse({ alm: AlmKeys.GitLab })]
+])('it should render correctly for %s', (_, projectBinding) => {
+  const wrapper = shallowRender({ projectBinding });
   expect(wrapper).toMatchSnapshot('wrapper');
   expect(renderStepContent(wrapper)).toMatchSnapshot('content');
 });
@@ -58,7 +43,7 @@ it.each([
 function shallowRender(props: Partial<WebhookStepProps> = {}) {
   return shallow<WebhookStepProps>(
     <WebhookStep
-      almBinding={mockBitbucketBindingDefinition()}
+      almBinding={mockAlmSettingsInstance()}
       branchesEnabled={true}
       finished={false}
       onDone={jest.fn()}
index 3c7034bff7dbabf9c8cf7ba17a99397bf2042312..f9417a75ab9e46d4ca6b2d0c0f4549abb0652be3 100644 (file)
@@ -20,7 +20,7 @@
 import { shallow } from 'enzyme';
 import * as React from 'react';
 import {
-  mockBitbucketBindingDefinition,
+  mockAlmSettingsInstance,
   mockProjectBitbucketBindingResponse
 } from '../../../../helpers/mocks/alm-settings';
 import WebhookStepBitbucket, { WebhookStepBitbucketProps } from '../WebhookStepBitbucket';
@@ -34,7 +34,7 @@ it('should render correctly', () => {
 function shallowRender(props: Partial<WebhookStepBitbucketProps> = {}) {
   return shallow<WebhookStepBitbucketProps>(
     <WebhookStepBitbucket
-      almBinding={mockBitbucketBindingDefinition()}
+      almBinding={mockAlmSettingsInstance({ url: 'http://bbs.enterprise.com' })}
       branchesEnabled={true}
       projectBinding={mockProjectBitbucketBindingResponse()}
       {...props}
index 4194473ddbca3a9625468f547291f6215610c3a5..6c0418f8d12383ab82e95eefb5ed26ffa2670dfe 100644 (file)
@@ -20,7 +20,7 @@
 import { shallow } from 'enzyme';
 import * as React from 'react';
 import {
-  mockGithubBindingDefinition,
+  mockAlmSettingsInstance,
   mockProjectGithubBindingResponse
 } from '../../../../helpers/mocks/alm-settings';
 import WebhookStepGithub, { WebhookStepGithubProps } from '../WebhookStepGithub';
@@ -34,7 +34,7 @@ it('should render correctly', () => {
 function shallowRender(props: Partial<WebhookStepGithubProps> = {}) {
   return shallow<WebhookStepGithubProps>(
     <WebhookStepGithub
-      almBinding={mockGithubBindingDefinition()}
+      almBinding={mockAlmSettingsInstance({ url: 'http://github.enterprise.com/api/v3' })}
       branchesEnabled={true}
       projectBinding={mockProjectGithubBindingResponse()}
       {...props}
index e5efd1b0cfd69d10a428014e72655f7743b0c61c..303c33d87525f58705cff533c1aa665e8eddc3b2 100644 (file)
@@ -169,8 +169,9 @@ exports[`should render correctly: content for github 1`] = `
             />
           </li>
           <li>
-            <LabelActionPair
+            <LabelValuePair
               translationKey="onboarding.tutorial.with.jenkins.multi_branch_pipeline.step2.github.repo_url"
+              value="https://github.com/PROJECT_KEY"
             />
           </li>
         </React.Fragment>
index 17b5fd12b0f51d2de46169f4f5822f8a8c711481..b311ac84df700b780ed3421f55f42554e3857094 100644 (file)
@@ -70,9 +70,8 @@ exports[`it should render correctly for bitbucket: content 1`] = `
     <WebhookStepBitbucket
       almBinding={
         Object {
+          "alm": "github",
           "key": "key",
-          "personalAccessToken": "asdf1234",
-          "url": "http://bbs.enterprise.com",
         }
       }
       branchesEnabled={true}
@@ -133,12 +132,8 @@ exports[`it should render correctly for github: content 1`] = `
     <WebhookStepGithub
       almBinding={
         Object {
-          "appId": "123456",
-          "clientId": "client1",
-          "clientSecret": "**clientsecret**",
+          "alm": "github",
           "key": "key",
-          "privateKey": "asdf1234",
-          "url": "http://github.enterprise.com",
         }
       }
       branchesEnabled={true}
index 647d92d4a4c014a7d3f4fd4c93d6eb529cfe3a38..9e4e661f700507e8023962c9bcc76d8d2c2eb6aa 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { GithubBindingDefinition, ProjectAlmBindingResponse } from '../../types/alm-settings';
+import { AlmSettingsInstance, ProjectAlmBindingResponse } from '../../types/alm-settings';
 
 export function quote(os: string): (s: string) => string {
   return os === 'win' ? (s: string) => `"${s}"` : (s: string) => s;
@@ -56,9 +56,13 @@ export function getUniqueTokenName(tokens: T.UserToken[], initialTokenName = '')
 }
 
 export function buildGithubLink(
-  almBinding: GithubBindingDefinition,
+  almBinding: AlmSettingsInstance,
   projectBinding: ProjectAlmBindingResponse
 ) {
+  if (almBinding.url === undefined) {
+    return null;
+  }
+
   // strip the api path:
   const urlRoot = almBinding.url
     .replace(/\/api\/v\d+\/?$/, '') // GH Enterprise