});
}
-export function importBitbucketServerProject(
- almSetting: string,
- projectKey: string,
- repositorySlug: string
-): Promise<{ project: ProjectBase }> {
- return postJSON('/api/alm_integrations/import_bitbucketserver_project', {
- almSetting,
- projectKey,
- repositorySlug,
- }).catch(throwGlobalError);
+export function setupBitbucketServerProjectCreation(data: {
+ almSetting: string;
+ projectKey: string;
+ repositorySlug: string;
+}) {
+ return (newCodeDefinitionType?: string, newCodeDefinitionValue?: string) =>
+ importBitbucketServerProject({ ...data, newCodeDefinitionType, newCodeDefinitionValue });
+}
+
+export function importBitbucketServerProject(data: {
+ almSetting: string;
+ projectKey: string;
+ repositorySlug: string;
+ newCodeDefinitionType?: string;
+ newCodeDefinitionValue?: string;
+}): Promise<{ project: ProjectBase }> {
+ return postJSON('/api/alm_integrations/import_bitbucketserver_project', data).catch(
+ throwGlobalError
+ );
}
export function searchForBitbucketServerRepositories(
searchForBitbucketServerRepositories,
setAlmPersonalAccessToken,
setupAzureProjectCreation,
+ setupBitbucketServerProjectCreation,
} from '../alm-integrations';
export default class AlmIntegrationsServiceMock {
.mocked(getBitbucketServerRepositories)
.mockImplementation(this.getBitbucketServerRepositories);
jest.mocked(importBitbucketServerProject).mockImplementation(this.importBitbucketServerProject);
+ jest
+ .mocked(setupBitbucketServerProjectCreation)
+ .mockReturnValue(() => this.importBitbucketServerProject());
jest
.mocked(searchForBitbucketServerRepositories)
.mockImplementation(this.searchForBitbucketServerRepositories);
BitbucketProjectRepositories,
BitbucketRepository,
} from '../../../../types/alm-integration';
-import InstanceNewCodeDefinitionComplianceWarning from '../components/InstanceNewCodeDefinitionComplianceWarning';
import { CreateProjectModes } from '../types';
import BitbucketRepositories from './BitbucketRepositories';
import BitbucketSearchResults from './BitbucketSearchResults';
export interface BitbucketImportRepositoryFormProps {
- disableRepositories: boolean;
onSearch: (query: string) => void;
onSelectRepository: (repo: BitbucketRepository) => void;
projects?: BitbucketProject[];
export default function BitbucketImportRepositoryForm(props: BitbucketImportRepositoryFormProps) {
const {
- disableRepositories,
projects = [],
projectRepositories = {},
searchResults,
return (
<div className="create-project-import-bbs">
- <InstanceNewCodeDefinitionComplianceWarning />
-
<SearchBox
onChange={props.onSearch}
placeholder={translate('onboarding.create_project.search_repositories_by_name')}
{searching || searchResults ? (
<BitbucketSearchResults
- disableRepositories={disableRepositories}
onSelectRepository={props.onSelectRepository}
projects={projects}
searchResults={searchResults}
/>
) : (
<BitbucketRepositories
- disableRepositories={disableRepositories}
onSelectRepository={props.onSelectRepository}
projectRepositories={projectRepositories}
projects={projects}
import { CreateProjectModes } from '../types';
export interface BitbucketProjectAccordionProps {
- disableRepositories: boolean;
onClick?: () => void;
onSelectRepository: (repo: BitbucketRepository) => void;
open: boolean;
}
export default function BitbucketProjectAccordion(props: BitbucketProjectAccordionProps) {
- const {
- disableRepositories,
- open,
- project,
- repositories,
- selectedRepository,
- showingAllRepositories,
- } = props;
+ const { open, project, repositories, selectedRepository, showingAllRepositories } = props;
const repositoryCount = repositories.length;
) : (
<Radio
checked={selectedRepository?.id === repo.id}
- className={classNames(
- 'display-flex-start spacer-right spacer-bottom create-project-import-bbs-repo overflow-hidden',
- {
- disabled: disableRepositories,
- }
- )}
+ className="display-flex-start spacer-right spacer-bottom create-project-import-bbs-repo overflow-hidden"
key={repo.id}
onCheck={() => props.onSelectRepository(repo)}
value={String(repo.id)}
import {
getBitbucketServerProjects,
getBitbucketServerRepositories,
- importBitbucketServerProject,
searchForBitbucketServerRepositories,
+ setupBitbucketServerProjectCreation,
} from '../../../../api/alm-integrations';
import { Location, Router } from '../../../../components/hoc/withRouter';
import {
} from '../../../../types/alm-integration';
import { AlmSettingsInstance } from '../../../../types/alm-settings';
import { DEFAULT_BBS_PAGE_SIZE } from '../constants';
+import { CreateProjectApiCallback } from '../types';
import BitbucketCreateProjectRenderer from './BitbucketProjectCreateRenderer';
interface Props {
canAdmin: boolean;
almInstances: AlmSettingsInstance[];
loadingBindings: boolean;
- onProjectCreate: (projectKey: string) => void;
location: Location;
router: Router;
+ onProjectSetupDone: (createProject: CreateProjectApiCallback) => void;
}
interface State {
selectedAlmInstance?: AlmSettingsInstance;
- importing: boolean;
loading: boolean;
projects?: BitbucketProject[];
projectRepositories?: BitbucketProjectRepositories;
constructor(props: Props) {
super(props);
this.state = {
- // For now, we only handle a single instance. So we always use the first
- // one from the list.
selectedAlmInstance: props.almInstances[0],
- importing: false,
loading: false,
searching: false,
showPersonalAccessTokenForm: true,
handleImportRepository = () => {
const { selectedAlmInstance, selectedRepository } = this.state;
- if (!selectedAlmInstance || !selectedRepository) {
- return;
+ if (selectedAlmInstance && selectedRepository) {
+ this.props.onProjectSetupDone(
+ setupBitbucketServerProjectCreation({
+ almSetting: selectedAlmInstance.key,
+ projectKey: selectedRepository.projectKey,
+ repositorySlug: selectedRepository.slug,
+ })
+ );
}
-
- this.setState({ importing: true });
- importBitbucketServerProject(
- selectedAlmInstance.key,
- selectedRepository.projectKey,
- selectedRepository.slug
- )
- .then(({ project: { key } }) => {
- if (this.mounted) {
- this.setState({ importing: false });
- this.props.onProjectCreate(key);
- }
- })
- .catch(() => {
- if (this.mounted) {
- this.setState({ importing: false });
- }
- });
};
handleSearch = (query: string) => {
const { canAdmin, loadingBindings, location, almInstances } = this.props;
const {
selectedAlmInstance,
- importing,
loading,
projectRepositories,
projects,
selectedAlmInstance={selectedAlmInstance}
almInstances={almInstances}
canAdmin={canAdmin}
- importing={importing}
loading={loading || loadingBindings}
onImportRepository={this.handleImportRepository}
onPersonalAccessTokenCreated={this.handlePersonalAccessTokenCreated}
*/
import * as React from 'react';
import { Button } from '../../../../components/controls/buttons';
-import DeferredSpinner from '../../../../components/ui/DeferredSpinner';
import { translate } from '../../../../helpers/l10n';
import { getBaseUrl } from '../../../../helpers/system';
import {
selectedAlmInstance?: AlmSettingsInstance;
almInstances: AlmSettingsInstance[];
canAdmin?: boolean;
- importing: boolean;
loading: boolean;
onImportRepository: () => void;
onSearch: (query: string) => void;
almInstances,
selectedAlmInstance,
canAdmin,
- importing,
loading,
projects,
projectRepositories,
additionalActions={
!showPersonalAccessTokenForm && (
<div className="display-flex-center pull-right">
- <DeferredSpinner className="spacer-right" loading={importing} />
<Button
className="button-large button-primary"
- disabled={!selectedRepository || importing}
+ disabled={!selectedRepository}
onClick={props.onImportRepository}
>
{translate('onboarding.create_project.import_selected_repo')}
/>
) : (
<BitbucketImportRepositoryForm
- disableRepositories={importing}
onSearch={props.onSearch}
onSelectRepository={props.onSelectRepository}
projectRepositories={projectRepositories}
import BitbucketProjectAccordion from './BitbucketProjectAccordion';
export interface BitbucketRepositoriesProps {
- disableRepositories: boolean;
onSelectRepository: (repo: BitbucketRepository) => void;
projects: BitbucketProject[];
projectRepositories: BitbucketProjectRepositories;
}
export default function BitbucketRepositories(props: BitbucketRepositoriesProps) {
- const { disableRepositories, projects, projectRepositories, selectedRepository } = props;
+ const { projects, projectRepositories, selectedRepository } = props;
const [openProjectKeys, setOpenProjectKeys] = React.useState(
projects.length > 0 ? [projects[0].key] : []
return (
<BitbucketProjectAccordion
- disableRepositories={disableRepositories}
key={project.key}
onClick={() => handleClick(isOpen, project.key)}
onSelectRepository={props.onSelectRepository}
import BitbucketProjectAccordion from './BitbucketProjectAccordion';
export interface BitbucketSearchResultsProps {
- disableRepositories: boolean;
onSelectRepository: (repo: BitbucketRepository) => void;
projects: BitbucketProject[];
searching: boolean;
}
export default function BitbucketSearchResults(props: BitbucketSearchResultsProps) {
- const {
- disableRepositories,
- projects,
- searching,
- searchResults = [],
- selectedRepository,
- } = props;
+ const { projects, searching, searchResults = [], selectedRepository } = props;
if (searchResults.length === 0 && !searching) {
return (
<DeferredSpinner loading={searching}>
{filteredSearchResults.length > 0 && (
<BitbucketProjectAccordion
- disableRepositories={disableRepositories}
onSelectRepository={props.onSelectRepository}
open
repositories={filteredSearchResults}
return (
<BitbucketProjectAccordion
- disableRepositories={disableRepositories}
key={project.key}
onSelectRepository={props.onSelectRepository}
open
almInstances={bitbucketSettings}
loadingBindings={loading}
location={location}
- onProjectCreate={this.handleProjectCreate}
router={router}
+ onProjectSetupDone={this.handleProjectSetupDone}
/>
);
}
await user.click(radioButton);
expect(importButton).toBeEnabled();
await user.click(importButton);
+
+ 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();
});