return getJSON('/api/alm_integrations/get_github_client_id', { almSetting });
}
-export function importBitbucketCloudRepository(
- almSetting: string,
- repositorySlug: string
-): Promise<{ project: ProjectBase }> {
- return postJSON('/api/alm_integrations/import_bitbucketcloud_repo', {
- almSetting,
- repositorySlug,
- }).catch(throwGlobalError);
+export function setupBitbucketCloudProjectCreation(data: {
+ almSetting: string;
+ repositorySlug: string;
+}) {
+ return (newCodeDefinitionType?: string, newCodeDefinitionValue?: string) =>
+ importBitbucketCloudRepository({ ...data, newCodeDefinitionType, newCodeDefinitionValue });
+}
+
+export function importBitbucketCloudRepository(data: {
+ almSetting: string;
+ repositorySlug: string;
+ newCodeDefinitionType?: string;
+ newCodeDefinitionValue?: string;
+}): Promise<{ project: ProjectBase }> {
+ return postJSON('/api/alm_integrations/import_bitbucketcloud_repo', data).catch(throwGlobalError);
}
export function importGithubRepository(
searchForBitbucketServerRepositories,
setAlmPersonalAccessToken,
setupAzureProjectCreation,
+ setupBitbucketCloudProjectCreation,
setupBitbucketServerProjectCreation,
} from '../alm-integrations';
jest.mocked(setAlmPersonalAccessToken).mockImplementation(this.setAlmPersonalAccessToken);
jest.mocked(getGitlabProjects).mockImplementation(this.getGitlabProjects);
jest.mocked(importGitlabProject).mockImplementation(this.importProject);
+ jest.mocked(setupBitbucketCloudProjectCreation).mockReturnValue(() => this.importProject());
jest.mocked(importBitbucketCloudRepository).mockImplementation(this.importProject);
jest.mocked(getGithubClientId).mockImplementation(this.getGithubClientId);
jest.mocked(getGithubOrganizations).mockImplementation(this.getGithubOrganizations);
*/
import * as React from 'react';
import {
- importBitbucketCloudRepository,
searchForBitbucketCloudRepositories,
+ setupBitbucketCloudProjectCreation,
} from '../../../../api/alm-integrations';
import { Location, Router } from '../../../../components/hoc/withRouter';
import { BitbucketCloudRepository } from '../../../../types/alm-integration';
import { AlmSettingsInstance } from '../../../../types/alm-settings';
import { Paging } from '../../../../types/types';
+import { CreateProjectApiCallback } from '../types';
import BitbucketCloudProjectCreateRenderer from './BitbucketCloudProjectCreateRender';
interface Props {
canAdmin: boolean;
almInstances: AlmSettingsInstance[];
loadingBindings: boolean;
- onProjectCreate: (projectKey: string) => void;
location: Location;
router: Router;
+ onProjectSetupDone: (createProject: CreateProjectApiCallback) => void;
}
interface State {
- importingSlug?: string;
isLastPage?: boolean;
loading: boolean;
loadingMore: boolean;
);
};
- handleImport = async (repositorySlug: string) => {
+ handleImport = (repositorySlug: string) => {
const { selectedAlmInstance } = this.state;
- if (!selectedAlmInstance) {
- return;
- }
-
- this.setState({ importingSlug: repositorySlug });
-
- const result = await importBitbucketCloudRepository(
- selectedAlmInstance.key,
- repositorySlug
- ).catch(() => undefined);
-
- if (this.mounted) {
- this.setState({ importingSlug: undefined });
-
- if (result) {
- this.props.onProjectCreate(result.project.key);
- }
+ if (selectedAlmInstance) {
+ this.props.onProjectSetupDone(
+ setupBitbucketCloudProjectCreation({
+ almSetting: selectedAlmInstance.key,
+ repositorySlug,
+ })
+ );
}
};
render() {
const { canAdmin, loadingBindings, location, almInstances } = this.props;
const {
- importingSlug,
isLastPage = true,
selectedAlmInstance,
loading,
} = this.state;
return (
<BitbucketCloudProjectCreateRenderer
- importingSlug={importingSlug}
isLastPage={isLastPage}
selectedAlmInstance={selectedAlmInstance}
almInstances={almInstances}
import BitbucketCloudSearchForm from './BitbucketCloudSearchForm';
export interface BitbucketCloudProjectCreateRendererProps {
- importingSlug?: string;
isLastPage: boolean;
canAdmin?: boolean;
loading: boolean;
) {
const {
almInstances,
- importingSlug,
isLastPage,
selectedAlmInstance,
canAdmin,
/>
) : (
<BitbucketCloudSearchForm
- importingSlug={importingSlug}
isLastPage={isLastPage}
loadingMore={loadingMore}
searchQuery={searchQuery}
import { BitbucketCloudRepository } from '../../../../types/alm-integration';
import { ComponentQualifier } from '../../../../types/component';
import { MetricType } from '../../../../types/metrics';
-import InstanceNewCodeDefinitionComplianceWarning from '../components/InstanceNewCodeDefinitionComplianceWarning';
import { CreateProjectModes } from '../types';
export interface BitbucketCloudSearchFormProps {
- importingSlug?: string;
isLastPage: boolean;
loadingMore: boolean;
onImport: (repositorySlug: string) => void;
}
export default function BitbucketCloudSearchForm(props: BitbucketCloudSearchFormProps) {
- const {
- importingSlug,
- isLastPage,
- loadingMore,
- repositories = [],
- searching,
- searchQuery,
- } = props;
+ const { isLastPage, loadingMore, repositories = [], searching, searchQuery } = props;
if (repositories.length === 0 && searchQuery.length === 0 && !searching) {
return (
}
return (
- <>
- <InstanceNewCodeDefinitionComplianceWarning />
- <div className="boxed-group big-padded create-project-import">
- <SearchBox
- className="spacer"
- loading={searching}
- minLength={3}
- onChange={props.onSearch}
- placeholder={translate('onboarding.create_project.search_prompt')}
- />
+ <div className="boxed-group big-padded create-project-import">
+ <SearchBox
+ className="spacer"
+ loading={searching}
+ minLength={3}
+ onChange={props.onSearch}
+ placeholder={translate('onboarding.create_project.search_prompt')}
+ />
- <hr />
+ <hr />
- {repositories.length === 0 ? (
- <div className="padded">{translate('no_results')}</div>
- ) : (
- <table className="data zebra zebra-hover">
- <tbody>
- {repositories.map((repository) => (
- <tr key={repository.uuid}>
+ {repositories.length === 0 ? (
+ <div className="padded">{translate('no_results')}</div>
+ ) : (
+ <table className="data zebra zebra-hover">
+ <tbody>
+ {repositories.map((repository) => (
+ <tr key={repository.uuid}>
+ <td>
+ <Tooltip overlay={repository.slug}>
+ <strong className="project-name display-inline-block text-ellipsis">
+ {repository.sqProjectKey ? (
+ <Link to={getProjectUrl(repository.sqProjectKey)}>
+ <QualifierIcon
+ className="spacer-right"
+ qualifier={ComponentQualifier.Project}
+ />
+ {repository.name}
+ </Link>
+ ) : (
+ repository.name
+ )}
+ </strong>
+ </Tooltip>
+ <br />
+ <Tooltip overlay={repository.projectKey}>
+ <span className="text-muted project-path display-inline-block text-ellipsis">
+ {repository.projectKey}
+ </span>
+ </Tooltip>
+ </td>
+ <td>
+ <Link
+ className="display-inline-flex-center big-spacer-right"
+ to={getRepositoryUrl(repository.workspace, repository.slug)}
+ target="_blank"
+ >
+ {translate('onboarding.create_project.bitbucketcloud.link')}
+ </Link>
+ </td>
+ {repository.sqProjectKey ? (
<td>
- <Tooltip overlay={repository.slug}>
- <strong className="project-name display-inline-block text-ellipsis">
- {repository.sqProjectKey ? (
- <Link to={getProjectUrl(repository.sqProjectKey)}>
- <QualifierIcon
- className="spacer-right"
- qualifier={ComponentQualifier.Project}
- />
- {repository.name}
- </Link>
- ) : (
- repository.name
- )}
- </strong>
- </Tooltip>
- <br />
- <Tooltip overlay={repository.projectKey}>
- <span className="text-muted project-path display-inline-block text-ellipsis">
- {repository.projectKey}
- </span>
- </Tooltip>
+ <span className="display-flex-center display-flex-justify-end already-set-up">
+ <CheckIcon className="little-spacer-right" size={12} />
+ {translate('onboarding.create_project.repository_imported')}
+ </span>
</td>
- <td>
- <Link
- className="display-inline-flex-center big-spacer-right"
- to={getRepositoryUrl(repository.workspace, repository.slug)}
- target="_blank"
+ ) : (
+ <td className="text-right">
+ <Button
+ onClick={() => {
+ props.onImport(repository.slug);
+ }}
>
- {translate('onboarding.create_project.bitbucketcloud.link')}
- </Link>
+ {translate('onboarding.create_project.set_up')}
+ </Button>
</td>
- {repository.sqProjectKey ? (
- <td>
- <span className="display-flex-center display-flex-justify-end already-set-up">
- <CheckIcon className="little-spacer-right" size={12} />
- {translate('onboarding.create_project.repository_imported')}
- </span>
- </td>
- ) : (
- <td className="text-right">
- <Button
- disabled={Boolean(importingSlug)}
- onClick={() => {
- props.onImport(repository.slug);
- }}
- >
- {translate('onboarding.create_project.set_up')}
- <DeferredSpinner
- className="spacer-left"
- loading={importingSlug === repository.slug}
- />
- </Button>
- </td>
- )}
- </tr>
- ))}
- </tbody>
- </table>
- )}
- <footer className="spacer-top note text-center">
- {isLastPage &&
- translateWithParameters(
- 'x_of_y_shown',
- formatMeasure(repositories.length, MetricType.Integer, null),
- formatMeasure(repositories.length, MetricType.Integer, null)
- )}
- {!isLastPage && (
- <Button
- className="spacer-left"
- disabled={loadingMore}
- data-test="show-more"
- onClick={props.onLoadMore}
- >
- {translate('show_more')}
- </Button>
+ )}
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ )}
+ <footer className="spacer-top note text-center">
+ {isLastPage &&
+ translateWithParameters(
+ 'x_of_y_shown',
+ formatMeasure(repositories.length, MetricType.Integer, null),
+ formatMeasure(repositories.length, MetricType.Integer, null)
)}
- <DeferredSpinner
- className="text-bottom spacer-left position-absolute"
- loading={loadingMore}
- />
- </footer>
- </div>
- </>
+ {!isLastPage && (
+ <Button
+ className="spacer-left"
+ disabled={loadingMore}
+ data-test="show-more"
+ onClick={props.onLoadMore}
+ >
+ {translate('show_more')}
+ </Button>
+ )}
+ <DeferredSpinner
+ className="text-bottom spacer-left position-absolute"
+ loading={loadingMore}
+ />
+ </footer>
+ </div>
);
}
canAdmin={!!canAdmin}
loadingBindings={loading}
location={location}
- onProjectCreate={this.handleProjectCreate}
+ onProjectSetupDone={this.handleProjectSetupDone}
router={router}
almInstances={bitbucketCloudSettings}
/>
expect(screen.getByText('BitbucketCloud Repo 1')).toBeInTheDocument();
expect(screen.getByText('BitbucketCloud Repo 2')).toBeInTheDocument();
- projectItem = screen.getByRole('row', {
- name: 'qualifier.TRK BitbucketCloud Repo 1 project opens_in_new_window onboarding.create_project.bitbucketcloud.link onboarding.create_project.repository_imported',
- });
+ projectItem = screen.getByRole('row', { name: /BitbucketCloud Repo 1/ });
expect(
within(projectItem).getByText('onboarding.create_project.repository_imported')
).toBeInTheDocument();
'/dashboard?id=key'
);
- projectItem = screen.getByRole('row', {
- name: 'BitbucketCloud Repo 2 project opens_in_new_window onboarding.create_project.bitbucketcloud.link onboarding.create_project.set_up',
- });
- const importProjectButton = within(projectItem).getByRole('button', {
+ projectItem = screen.getByRole('row', { name: /BitbucketCloud Repo 2/ });
+ const setupButton = within(projectItem).getByRole('button', {
name: 'onboarding.create_project.set_up',
});
- await user.click(importProjectButton);
+ await user.click(setupButton);
+
+ expect(
+ screen.getByRole('heading', { name: 'onboarding.create_project.new_code_definition.title' })
+ ).toBeInTheDocument();
+
+ await user.click(screen.getByRole('radio', { name: 'new_code_definition.global_setting' }));
+ await user.click(
+ screen.getByRole('button', {
+ name: 'onboarding.create_project.new_code_definition.create_project',
+ })
+ );
+
expect(await screen.findByText('/dashboard?id=key')).toBeInTheDocument();
});