} 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> {
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';
}
interface State {
- almBinding?: AlmBindingDefinition;
+ almBinding?: AlmSettingsInstance;
baseUrl: string;
forceManual: boolean;
loading: boolean;
}
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 });
}
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';
import { TutorialModes } from './types';
export interface TutorialSelectionRendererProps {
- almBinding?: AlmBindingDefinition;
+ almBinding?: AlmSettingsInstance;
baseUrl: string;
component: T.Component;
currentUser: T.LoggedInUser;
<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
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 {
mockLoggedInUser,
mockRouter
} from '../../../helpers/testMocks';
-import { AlmKeys } from '../../../types/alm-settings';
import { SettingsKey } from '../../../types/settings';
import { TutorialSelection } from '../TutorialSelection';
import { TutorialModes } from '../types';
}));
jest.mock('../../../api/alm-settings', () => ({
- getAlmDefinitionsNoCatch: jest.fn().mockRejectedValue(null)
+ getAlmSettingsNoCatch: jest.fn().mockRejectedValue(null)
}));
jest.mock('../../../api/settings', () => ({
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);
import * as React from 'react';
import { click } from 'sonar-ui-common/helpers/testUtils';
import {
- mockBitbucketBindingDefinition,
- mockGithubBindingDefinition,
+ mockAlmSettingsInstance,
mockProjectAzureBindingResponse,
mockProjectBitbucketBindingResponse,
mockProjectGithubBindingResponse,
).toMatchSnapshot('jenkins tutorial');
expect(
shallowRender({
- almBinding: mockGithubBindingDefinition(),
selectedTutorial: TutorialModes.GitHubActions,
projectBinding: mockProjectGithubBindingResponse()
})
function shallowRender(props: Partial<TutorialSelectionRendererProps> = {}) {
return shallow<TutorialSelectionRendererProps>(
<TutorialSelectionRenderer
- almBinding={mockBitbucketBindingDefinition()}
+ almBinding={mockAlmSettingsInstance()}
baseUrl="http://localhost:9000"
component={mockComponent()}
currentUser={mockLoggedInUser()}
<GitHubActionTutorial
almBinding={
Object {
- "appId": "123456",
- "clientId": "client1",
- "clientSecret": "**clientsecret**",
+ "alm": "github",
"key": "key",
- "privateKey": "asdf1234",
- "url": "http://github.enterprise.com",
}
}
baseUrl="http://localhost:9000"
<Connect(JenkinsTutorial)
almBinding={
Object {
+ "alm": "github",
"key": "key",
- "personalAccessToken": "asdf1234",
- "url": "http://bbs.enterprise.com",
}
}
component={
* 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';
});
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();
+ });
});
*/
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';
}
export interface GitHubActionTutorialProps {
- almBinding?: GithubBindingDefinition;
+ almBinding?: AlmSettingsInstance;
baseUrl: string;
component: T.Component;
currentUser: T.LoggedInUser;
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;
import { shallow } from 'enzyme';
import * as React from 'react';
import {
- mockGithubBindingDefinition,
+ mockAlmSettingsInstance,
mockProjectGithubBindingResponse
} from '../../../../helpers/mocks/alm-settings';
import { mockComponent, mockLoggedInUser } from '../../../../helpers/testMocks';
function shallowRender(props: Partial<GitHubActionTutorialProps> = {}) {
return shallow<GitHubActionTutorialProps>(
<GitHubActionTutorial
- almBinding={mockGithubBindingDefinition()}
+ almBinding={mockAlmSettingsInstance()}
baseUrl="test"
currentUser={mockLoggedInUser()}
component={mockComponent()}
import { shallow } from 'enzyme';
import * as React from 'react';
import {
- mockGithubBindingDefinition,
+ mockAlmSettingsInstance,
mockProjectGithubBindingResponse
} from '../../../../helpers/mocks/alm-settings';
import { mockComponent, mockLoggedInUser } from '../../../../helpers/testMocks';
expect(shallowRender()).toMatchSnapshot('default');
expect(
shallowRender({
- almBinding: mockGithubBindingDefinition()
+ almBinding: mockAlmSettingsInstance({ url: 'http://github.enterprise.com/api/v3' })
})
).toMatchSnapshot('with binding information');
});
import { getAppState, getCurrentUserSetting, Store } from '../../../store/rootReducer';
import { setCurrentUserSetting } from '../../../store/users';
import {
- AlmBindingDefinition,
+ AlmSettingsInstance,
isProjectBitbucketBindingResponse,
isProjectGitHubBindingResponse,
isProjectGitLabBindingResponse,
import WebhookStep from './WebhookStep';
export interface JenkinsTutorialProps {
- almBinding?: AlmBindingDefinition;
+ almBinding?: AlmSettingsInstance;
branchesEnabled: boolean;
component: T.Component;
projectBinding: ProjectAlmBindingResponse;
import { Button } from 'sonar-ui-common/components/controls/buttons';
import { translate } from 'sonar-ui-common/helpers/l10n';
import {
- AlmBindingDefinition,
- isGithubBindingDefinition,
+ AlmSettingsInstance,
isProjectBitbucketBindingResponse,
isProjectGitHubBindingResponse,
isProjectGitLabBindingResponse,
import { buildGithubLink } from '../utils';
export interface MultiBranchPipelineStepProps {
- almBinding?: AlmBindingDefinition;
+ almBinding?: AlmSettingsInstance;
finished: boolean;
onDone: () => void;
onOpen: () => void;
<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" />
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';
import WebhookStepGitLab from './WebhookStepGitLab';
export interface WebhookStepProps {
- almBinding?: AlmBindingDefinition;
+ almBinding?: AlmSettingsInstance;
branchesEnabled: boolean;
finished: boolean;
onDone: () => void;
case AlmKeys.BitbucketServer:
return (
<WebhookStepBitbucket
- almBinding={isBitbucketBindingDefinition(almBinding) ? almBinding : undefined}
+ almBinding={almBinding}
branchesEnabled={branchesEnabled}
projectBinding={projectBinding}
/>
case AlmKeys.GitHub:
return (
<WebhookStepGithub
- almBinding={isGithubBindingDefinition(almBinding) ? almBinding : undefined}
+ almBinding={almBinding}
branchesEnabled={branchesEnabled}
projectBinding={projectBinding}
/>
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;
}
const linkUrl =
almBinding &&
+ almBinding.url &&
`${almBinding.url}/plugins/servlet/webhooks/projects/${projectBinding.repository}/repos/${projectBinding.slug}/create`;
return (
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;
}
import { shallow } from 'enzyme';
import * as React from 'react';
import {
+ mockAlmSettingsInstance,
mockProjectBitbucketBindingResponse,
mockProjectGithubBindingResponse,
mockProjectGitLabBindingResponse
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() }))
import { shallow } from 'enzyme';
import * as React from 'react';
import {
- mockAzureBindingDefinition,
- mockBitbucketBindingDefinition,
- mockGithubBindingDefinition,
- mockGitlabBindingDefinition,
+ mockAlmSettingsInstance,
mockProjectAlmBindingResponse,
mockProjectBitbucketBindingResponse,
mockProjectGithubBindingResponse
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');
});
function shallowRender(props: Partial<WebhookStepProps> = {}) {
return shallow<WebhookStepProps>(
<WebhookStep
- almBinding={mockBitbucketBindingDefinition()}
+ almBinding={mockAlmSettingsInstance()}
branchesEnabled={true}
finished={false}
onDone={jest.fn()}
import { shallow } from 'enzyme';
import * as React from 'react';
import {
- mockBitbucketBindingDefinition,
+ mockAlmSettingsInstance,
mockProjectBitbucketBindingResponse
} from '../../../../helpers/mocks/alm-settings';
import WebhookStepBitbucket, { WebhookStepBitbucketProps } from '../WebhookStepBitbucket';
function shallowRender(props: Partial<WebhookStepBitbucketProps> = {}) {
return shallow<WebhookStepBitbucketProps>(
<WebhookStepBitbucket
- almBinding={mockBitbucketBindingDefinition()}
+ almBinding={mockAlmSettingsInstance({ url: 'http://bbs.enterprise.com' })}
branchesEnabled={true}
projectBinding={mockProjectBitbucketBindingResponse()}
{...props}
import { shallow } from 'enzyme';
import * as React from 'react';
import {
- mockGithubBindingDefinition,
+ mockAlmSettingsInstance,
mockProjectGithubBindingResponse
} from '../../../../helpers/mocks/alm-settings';
import WebhookStepGithub, { WebhookStepGithubProps } from '../WebhookStepGithub';
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}
/>
</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>
<WebhookStepBitbucket
almBinding={
Object {
+ "alm": "github",
"key": "key",
- "personalAccessToken": "asdf1234",
- "url": "http://bbs.enterprise.com",
}
}
branchesEnabled={true}
<WebhookStepGithub
almBinding={
Object {
- "appId": "123456",
- "clientId": "client1",
- "clientSecret": "**clientsecret**",
+ "alm": "github",
"key": "key",
- "privateKey": "asdf1234",
- "url": "http://github.enterprise.com",
}
}
branchesEnabled={true}
* 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;
}
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