return postJSON('/api/alm_integrations/import_bitbucketcloud_repo', data).catch(throwGlobalError);
}
-export function importGithubRepository(
- almSetting: string,
- organization: string,
- repositoryKey: string
-): Promise<{ project: ProjectBase }> {
- return postJSON('/api/alm_integrations/import_github_project', {
- almSetting,
- organization,
- repositoryKey,
- }).catch(throwGlobalError);
+export function setupGithubProjectCreation(data: {
+ almSetting: string;
+ organization: string;
+ repositoryKey: string;
+}) {
+ return (newCodeDefinitionType?: string, newCodeDefinitionValue?: string) =>
+ importGithubRepository({ ...data, newCodeDefinitionType, newCodeDefinitionValue });
+}
+
+export function importGithubRepository(data: {
+ almSetting: string;
+ organization: string;
+ repositoryKey: string;
+ newCodeDefinitionType?: string;
+ newCodeDefinitionValue?: string;
+}): Promise<{ project: ProjectBase }> {
+ return postJSON('/api/alm_integrations/import_github_project', data).catch(throwGlobalError);
}
export function getGithubOrganizations(
setupBitbucketCloudProjectCreation,
setupBitbucketServerProjectCreation,
setupGitlabProjectCreation,
+ setupGithubProjectCreation,
} from '../alm-integrations';
export default class AlmIntegrationsServiceMock {
jest.mocked(searchAzureRepositories).mockImplementation(this.searchAzureRepositories);
jest.mocked(setupAzureProjectCreation).mockReturnValue(() => this.importAzureRepository());
jest.mocked(importAzureRepository).mockImplementation(this.importAzureRepository);
+ jest.mocked(setupGithubProjectCreation).mockReturnValue(() => this.importGithubRepository());
jest.mocked(importGithubRepository).mockImplementation(this.importGithubRepository);
jest
.mocked(searchForBitbucketCloudRepositories)
canAdmin={!!canAdmin}
loadingBindings={loading}
location={location}
- onProjectCreate={this.handleProjectCreate}
+ onProjectSetupDone={this.handleProjectSetupDone}
router={router}
almInstances={githubSettings}
/>
getGithubClientId,
getGithubOrganizations,
getGithubRepositories,
- importGithubRepository,
+ setupGithubProjectCreation,
} from '../../../../api/alm-integrations';
import { Location, Router } from '../../../../components/hoc/withRouter';
import { getHostUrl } from '../../../../helpers/urls';
import { AlmKeys, AlmSettingsInstance } from '../../../../types/alm-settings';
import { Paging } from '../../../../types/types';
import GitHubProjectCreateRenderer from './GitHubProjectCreateRenderer';
+import { CreateProjectApiCallback } from '../types';
interface Props {
canAdmin: boolean;
loadingBindings: boolean;
- onProjectCreate: (projectKey: string) => void;
+ onProjectSetupDone: (createProject: CreateProjectApiCallback) => void;
almInstances: AlmSettingsInstance[];
location: Location;
router: Router;
interface State {
error: boolean;
- importing: boolean;
loadingOrganizations: boolean;
loadingRepositories: boolean;
organizations: GithubOrganization[];
this.state = {
error: false,
- importing: false,
loadingOrganizations: true,
loadingRepositories: false,
organizations: [],
}
};
- handleImportRepository = async () => {
+ handleImportRepository = () => {
const { selectedOrganization, selectedRepository, selectedAlmInstance } = this.state;
if (selectedAlmInstance && selectedOrganization && selectedRepository) {
- this.setState({ importing: true });
-
- try {
- const { project } = await importGithubRepository(
- selectedAlmInstance.key,
- selectedOrganization.key,
- selectedRepository.key
- );
-
- this.props.onProjectCreate(project.key);
- } finally {
- if (this.mounted) {
- this.setState({ importing: false });
- }
- }
+ this.props.onProjectSetupDone(
+ setupGithubProjectCreation({
+ almSetting: selectedAlmInstance.key,
+ organization: selectedOrganization.key,
+ repositoryKey: selectedRepository.key,
+ })
+ );
}
};
const { canAdmin, loadingBindings, almInstances } = this.props;
const {
error,
- importing,
loadingOrganizations,
loadingRepositories,
organizations,
<GitHubProjectCreateRenderer
canAdmin={canAdmin}
error={error}
- importing={importing}
loadingBindings={loadingBindings}
loadingOrganizations={loadingOrganizations}
loadingRepositories={loadingRepositories}
import { Paging } from '../../../../types/types';
import AlmSettingsInstanceDropdown from '../components/AlmSettingsInstanceDropdown';
import CreateProjectPageHeader from '../components/CreateProjectPageHeader';
-import InstanceNewCodeDefinitionComplianceWarning from '../components/InstanceNewCodeDefinitionComplianceWarning';
export interface GitHubProjectCreateRendererProps {
canAdmin: boolean;
error: boolean;
- importing: boolean;
loadingBindings: boolean;
loadingOrganizations: boolean;
loadingRepositories: boolean;
function renderRepositoryList(props: GitHubProjectCreateRendererProps) {
const {
- importing,
loadingRepositories,
repositories,
repositoryPaging,
(!!selectedRepository && selectedRepository.key === repository.key);
const isDisabled = (repository: GithubRepository) =>
- !!repository.sqProjectKey || loadingRepositories || importing;
+ !!repository.sqProjectKey || loadingRepositories;
return (
selectedOrganization &&
const {
canAdmin,
error,
- importing,
loadingBindings,
loadingOrganizations,
organizations,
additionalActions={
selectedOrganization && (
<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')}
)}
{!error && (
- <>
- <InstanceNewCodeDefinitionComplianceWarning />
- <DeferredSpinner loading={loadingOrganizations}>
- <div className="form-field">
- <label htmlFor="github-choose-organization">
- {translate('onboarding.create_project.github.choose_organization')}
- </label>
- {organizations.length > 0 ? (
- <Select
- inputId="github-choose-organization"
- className="input-super-large"
- options={organizations.map(orgToOption)}
- onChange={({ value }: LabelValueSelectOption) =>
- props.onSelectOrganization(value)
- }
- value={selectedOrganization ? orgToOption(selectedOrganization) : null}
- />
- ) : (
- !loadingOrganizations && (
- <Alert className="spacer-top" variant="error">
- {canAdmin ? (
- <FormattedMessage
- id="onboarding.create_project.github.no_orgs_admin"
- defaultMessage={translate('onboarding.create_project.github.no_orgs_admin')}
- values={{
- link: (
- <Link to="/admin/settings?category=almintegration">
- {translate(
- 'onboarding.create_project.github.warning.message_admin.link'
- )}
- </Link>
- ),
- }}
- />
- ) : (
- translate('onboarding.create_project.github.no_orgs')
- )}
- </Alert>
- )
- )}
- </div>
- </DeferredSpinner>
- </>
+ <DeferredSpinner loading={loadingOrganizations}>
+ <div className="form-field">
+ <label htmlFor="github-choose-organization">
+ {translate('onboarding.create_project.github.choose_organization')}
+ </label>
+ {organizations.length > 0 ? (
+ <Select
+ inputId="github-choose-organization"
+ className="input-super-large"
+ options={organizations.map(orgToOption)}
+ onChange={({ value }: LabelValueSelectOption) => props.onSelectOrganization(value)}
+ value={selectedOrganization ? orgToOption(selectedOrganization) : null}
+ />
+ ) : (
+ !loadingOrganizations && (
+ <Alert className="spacer-top" variant="error">
+ {canAdmin ? (
+ <FormattedMessage
+ id="onboarding.create_project.github.no_orgs_admin"
+ defaultMessage={translate('onboarding.create_project.github.no_orgs_admin')}
+ values={{
+ link: (
+ <Link to="/admin/settings?category=almintegration">
+ {translate(
+ 'onboarding.create_project.github.warning.message_admin.link'
+ )}
+ </Link>
+ ),
+ }}
+ />
+ ) : (
+ translate('onboarding.create_project.github.no_orgs')
+ )}
+ </Alert>
+ )
+ )}
+ </div>
+ </DeferredSpinner>
)}
{renderRepositoryList(props)}
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();
});