);
}
-export function importAzureRepository(
- almSetting: string,
- projectName: string,
- repositoryName: string
-): Promise<{ project: ProjectBase }> {
- return postJSON('/api/alm_integrations/import_azure_project', {
- almSetting,
- projectName,
- repositoryName,
- }).catch(throwGlobalError);
+export function setupAzureProjectCreation(data: {
+ almSetting: string;
+ projectName: string;
+ repositoryName: string;
+}) {
+ return (newCodeDefinitionType?: string, newCodeDefinitionValue?: string) =>
+ importAzureRepository({ ...data, newCodeDefinitionType, newCodeDefinitionValue });
+}
+
+export function importAzureRepository(data: {
+ almSetting: string;
+ projectName: string;
+ repositoryName: string;
+ newCodeDefinitionType?: string;
+ newCodeDefinitionValue?: string;
+}): Promise<{ project: ProjectBase }> {
+ return postJSON('/api/alm_integrations/import_azure_project', data).catch(throwGlobalError);
}
export function getBitbucketServerProjects(
searchForBitbucketCloudRepositories,
searchForBitbucketServerRepositories,
setAlmPersonalAccessToken,
+ setupAzureProjectCreation,
} from '../alm-integrations';
export default class AlmIntegrationsServiceMock {
jest.mocked(getAzureRepositories).mockImplementation(this.getAzureRepositories);
jest.mocked(getGithubRepositories).mockImplementation(this.getGithubRepositories);
jest.mocked(searchAzureRepositories).mockImplementation(this.searchAzureRepositories);
+ jest.mocked(setupAzureProjectCreation).mockReturnValue(() => this.importAzureRepository());
jest.mocked(importAzureRepository).mockImplementation(this.importAzureRepository);
jest.mocked(importGithubRepository).mockImplementation(this.importGithubRepository);
jest
import { CreateProjectModes } from '../types';
export interface AzureProjectAccordionProps {
- importing: boolean;
loading: boolean;
onOpen: (key: string) => void;
onSelectRepository: (repository: AzureRepository) => void;
export default function AzureProjectAccordion(props: AzureProjectAccordionProps) {
const {
- importing,
loading,
startsOpen,
project,
checked={isSelected(repo)}
className="overflow-hidden"
alignLabel
- disabled={importing}
onCheck={() => props.onSelectRepository(repo)}
value={repo.name}
>
checkPersonalAccessTokenIsValid,
getAzureProjects,
getAzureRepositories,
- importAzureRepository,
searchAzureRepositories,
setAlmPersonalAccessToken,
+ setupAzureProjectCreation,
} from '../../../../api/alm-integrations';
import { Location, Router } from '../../../../components/hoc/withRouter';
import { AzureProject, AzureRepository } from '../../../../types/alm-integration';
import { AlmSettingsInstance } from '../../../../types/alm-settings';
import { Dict } from '../../../../types/types';
+import { CreateProjectApiCallback } from '../types';
import { tokenExistedBefore } from '../utils';
import AzureCreateProjectRenderer from './AzureProjectCreateRenderer';
interface Props {
canAdmin: boolean;
loadingBindings: boolean;
- onProjectCreate: (projectKey: string) => void;
almInstances: AlmSettingsInstance[];
location: Location;
router: Router;
+ onProjectSetupDone: (createProject: CreateProjectApiCallback) => void;
}
interface State {
- importing: boolean;
loading: boolean;
loadingRepositories: Dict<boolean>;
patIsValid?: boolean;
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,
loadingRepositories: {},
repositories: {},
}
};
- handleImportRepository = async () => {
+ handleImportRepository = () => {
const { selectedRepository, selectedAlmInstance } = this.state;
- if (!selectedAlmInstance || !selectedRepository) {
- return;
- }
-
- this.setState({ importing: true });
-
- const createdProject = await importAzureRepository(
- selectedAlmInstance.key,
- selectedRepository.projectName,
- selectedRepository.name
- )
- .then(({ project }) => project)
- .catch(() => undefined);
-
- if (this.mounted) {
- this.setState({ importing: false });
- if (createdProject) {
- this.props.onProjectCreate(createdProject.key);
- }
+ if (selectedAlmInstance && selectedRepository) {
+ this.props.onProjectSetupDone(
+ setupAzureProjectCreation({
+ almSetting: selectedAlmInstance.key,
+ projectName: selectedRepository.projectName,
+ repositoryName: selectedRepository.name,
+ })
+ );
}
};
render() {
const { canAdmin, loadingBindings, location, almInstances } = this.props;
const {
- importing,
loading,
loadingRepositories,
patIsValid,
return (
<AzureCreateProjectRenderer
canAdmin={canAdmin}
- importing={importing}
loading={loading || loadingBindings}
loadingRepositories={loadingRepositories}
onImportRepository={this.handleImportRepository}
import { ALM_INTEGRATION_CATEGORY } from '../../../settings/constants';
import AlmSettingsInstanceDropdown from '../components/AlmSettingsInstanceDropdown';
import CreateProjectPageHeader from '../components/CreateProjectPageHeader';
-import InstanceNewCodeDefinitionComplianceWarning from '../components/InstanceNewCodeDefinitionComplianceWarning';
import WrongBindingCountAlert from '../components/WrongBindingCountAlert';
import AzurePersonalAccessTokenForm from './AzurePersonalAccessTokenForm';
import AzureProjectsList from './AzureProjectsList';
export interface AzureProjectCreateRendererProps {
canAdmin?: boolean;
- importing: boolean;
loading: boolean;
loadingRepositories: Dict<boolean>;
onImportRepository: () => void;
export default function AzureProjectCreateRenderer(props: AzureProjectCreateRendererProps) {
const {
canAdmin,
- importing,
loading,
loadingRepositories,
projects,
!showPersonalAccessTokenForm &&
settingIsValid && (
<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')}
</div>
) : (
<>
- <InstanceNewCodeDefinitionComplianceWarning />
-
<div className="huge-spacer-bottom">
<SearchBox
onChange={props.onSearch}
</div>
<DeferredSpinner loading={Boolean(searching)}>
<AzureProjectsList
- importing={importing}
loadingRepositories={loadingRepositories}
onOpenProject={props.onOpenProject}
onSelectRepository={props.onSelectRepository}
import AzureProjectAccordion from './AzureProjectAccordion';
export interface AzureProjectsListProps {
- importing: boolean;
loadingRepositories: Dict<boolean>;
onOpenProject: (key: string) => void;
onSelectRepository: (repository: AzureRepository) => void;
export default function AzureProjectsList(props: AzureProjectsListProps) {
const {
- importing,
loadingRepositories,
projects = [],
repositories,
{displayedProjects.map((p, i) => (
<AzureProjectAccordion
key={`${p.name}${keySuffix}`}
- importing={importing}
loading={Boolean(loadingRepositories[p.name])}
onOpen={props.onOpenProject}
onSelectRepository={props.onSelectRepository}
import AzureProjectCreate from './Azure/AzureProjectCreate';
import BitbucketCloudProjectCreate from './BitbucketCloud/BitbucketCloudProjectCreate';
import BitbucketProjectCreate from './BitbucketServer/BitbucketProjectCreate';
-import CreateProjectPageHeader from './components/CreateProjectPageHeader';
import CreateProjectModeSelection from './CreateProjectModeSelection';
import GitHubProjectCreate from './Github/GitHubProjectCreate';
import GitlabProjectCreate from './Gitlab/GitlabProjectCreate';
+import CreateProjectPageHeader from './components/CreateProjectPageHeader';
import ManualProjectCreate from './manual/ManualProjectCreate';
import './style.css';
import { CreateProjectApiCallback, CreateProjectModes } from './types';
canAdmin={!!canAdmin}
loadingBindings={loading}
location={location}
- onProjectCreate={this.handleProjectCreate}
router={router}
almInstances={azureSettings}
+ onProjectSetupDone={this.handleProjectSetupDone}
/>
);
}
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();
});