Skip to content

Commit

Permalink
Add fallback to builder image detection
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik committed Sep 9, 2020
1 parent d8ef91d commit 220eb47
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
Expand Up @@ -36,7 +36,9 @@ const EditApplicationForm: React.FC<FormikProps<FormikValues> & EditApplicationF
<>
<PageHeading title={createFlowType} style={{ padding: '0px' }} />
<Form onSubmit={handleSubmit}>
{createFlowType !== CreateApplicationFlow.Container && <GitSection />}
{createFlowType !== CreateApplicationFlow.Container && (
<GitSection builderImages={builderImages} />
)}
{createFlowType === CreateApplicationFlow.Git && (
<BuilderSection image={values.image} builderImages={builderImages} />
)}
Expand Down
Expand Up @@ -24,7 +24,7 @@ const GitImportForm: React.FC<FormikProps<FormikValues> & GitImportFormProps> =
projects,
}) => (
<Form onSubmit={handleSubmit} data-test-id="import-git-form">
<GitSection />
<GitSection builderImages={builderImages} />
<BuilderSection image={values.image} builderImages={builderImages} />
<DockerSection buildStrategy={values.build.strategy} />
<AppSection
Expand Down
Expand Up @@ -24,7 +24,7 @@ const SourceToImageForm: React.FC<FormikProps<FormikValues> & SourceToImageFormP
}) => (
<Form onSubmit={handleSubmit}>
<BuilderSection image={values.image} builderImages={builderImages} />
<GitSection showSample />
<GitSection showSample builderImages={builderImages} />
<AppSection
project={values.project}
noProjectsAvailable={projects.loaded && _.isEmpty(projects.data)}
Expand Down
@@ -1,7 +1,7 @@
import * as React from 'react';
import { useFormikContext, FormikValues, FormikTouched } from 'formik';
import { Alert, TextInputTypes, ValidatedOptions } from '@patternfly/react-core';
import { getGitService, GitProvider } from '@console/git-service';
import { getGitService, GitProvider, BuildType } from '@console/git-service';
import {
InputField,
DropdownField,
Expand All @@ -10,17 +10,23 @@ import {
} from '@console/shared';
import { GitReadableTypes, GitTypes } from '../import-types';
import { detectGitType, detectGitRepoName } from '../import-validation-utils';
import { getSampleRepo, getSampleRef, getSampleContextDir } from '../../../utils/imagestream-utils';
import {
getSampleRepo,
getSampleRef,
getSampleContextDir,
NormalizedBuilderImages,
} from '../../../utils/imagestream-utils';
import FormSection from '../section/FormSection';
import SampleRepo from './SampleRepo';
import AdvancedGitOptions from './AdvancedGitOptions';
import { UNASSIGNED_KEY, CREATE_APPLICATION_KEY } from '../../../const';

export interface GitSectionProps {
showSample?: boolean;
builderImages: NormalizedBuilderImages;
}

const GitSection: React.FC<GitSectionProps> = ({ showSample }) => {
const GitSection: React.FC<GitSectionProps> = ({ showSample, builderImages }) => {
const { values, setFieldValue, setFieldTouched, touched, dirty } = useFormikContext<
FormikValues
>();
Expand Down Expand Up @@ -56,12 +62,14 @@ const GitSection: React.FC<GitSectionProps> = ({ showSample }) => {
values.application.selectedKey !== UNASSIGNED_KEY &&
setFieldValue('application.name', `${gitRepoName}-app`);
setFieldValue('image.isRecommending', true);
const buildTools = await gitService.detectBuildTypes();
const buildTools: BuildType[] = await gitService.detectBuildTypes();
setFieldValue('image.isRecommending', false);
if (buildTools.length > 0) {
const buildTool = buildTools[0].buildType;
const buildTool = buildTools.find(
({ buildType: recommended }) => recommended && builderImages.hasOwnProperty(recommended),
);
if (buildTool && buildTool.buildType) {
setFieldValue('image.couldNotRecommend', false);
setFieldValue('image.recommended', buildTool);
setFieldValue('image.recommended', buildTool.buildType);
} else {
setFieldValue('image.couldNotRecommend', true);
setFieldValue('image.recommended', '');
Expand All @@ -73,6 +81,7 @@ const GitSection: React.FC<GitSectionProps> = ({ showSample }) => {
}
},
[
builderImages,
gitTypeTouched,
setFieldTouched,
setFieldValue,
Expand Down

0 comments on commit 220eb47

Please sign in to comment.