Skip to content

Commit

Permalink
Merge pull request backstage#3921 from goober/feature/catalog-import-…
Browse files Browse the repository at this point in the history
…descriptions

catalog-import: add support for multiple git providers
  • Loading branch information
freben authored Jan 12, 2021
2 parents ffa36ff + bc40cce commit d45a510
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/generic-catalog-import-descriptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-import': patch
---

Add more generic descriptions for the catalog-import form.
9 changes: 7 additions & 2 deletions plugins/catalog-import/src/components/ImportComponentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ const useStyles = makeStyles<BackstageTheme>(theme => ({
type Props = {
nextStep: () => void;
saveConfig: (configFile: ConfigSpec) => void;
repository: string;
};

export const RegisterComponentForm = ({ nextStep, saveConfig }: Props) => {
export const RegisterComponentForm = ({
nextStep,
saveConfig,
repository,
}: Props) => {
const { register, handleSubmit, errors, formState } = useForm({
mode: 'onChange',
});
Expand Down Expand Up @@ -103,7 +108,7 @@ export const RegisterComponentForm = ({ nextStep, saveConfig }: Props) => {
name="componentLocation"
required
margin="normal"
helperText="Enter the full path to the repository in GitHub to start tracking your component."
helperText={`Enter the full path to the repository in ${repository} to start tracking your component.`}
inputRef={register({
required: true,
validate: ComponentIdValidators,
Expand Down
67 changes: 53 additions & 14 deletions plugins/catalog-import/src/components/ImportComponentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import {
SupportButton,
ContentHeader,
RouteRef,
useApi,
configApiRef,
ConfigApi,
} from '@backstage/core';
import { RegisterComponentForm } from './ImportComponentForm';
import ImportStepper from './ImportStepper';
Expand All @@ -37,6 +40,28 @@ export type ConfigSpec = {
config: PartialEntity[];
};

function manifestGenerationAvailable(configApi: ConfigApi): boolean {
return configApi.has('integrations.github');
}

function repositories(configApi: ConfigApi): string[] {
const integrations = configApi.getConfig('integrations');
const repositories = [];
if (integrations.has('github')) {
repositories.push('GitHub');
}
if (integrations.has('bitbucket')) {
repositories.push('Bitbucket');
}
if (integrations.has('gitlab')) {
repositories.push('GitLab');
}
if (integrations.has('azure')) {
repositories.push('Azure');
}
return repositories;
}

export const ImportComponentPage = ({
catalogRouteRef,
}: {
Expand All @@ -53,13 +78,17 @@ export const ImportComponentPage = ({
setActiveStep(step => (options?.reset ? 0 : step + 1));
};

const configApi = useApi(configApiRef);
const appTitle = configApi.getOptional('app.title') || 'Backstage';
const repos = repositories(configApi);
const repositoryString = repos.join(', ').replace(/, (\w*)$/, ' or $1');
return (
<Page themeId="home">
<Header title="Register an existing component" />
<Content>
<ContentHeader title="Start tracking your component in Backstage">
<ContentHeader title={`Start tracking your component in ${appTitle}`}>
<SupportButton>
Start tracking your component in Backstage by adding it to the
Start tracking your component in {appTitle} by adding it to the
software catalog.
</SupportButton>
</ContentHeader>
Expand All @@ -73,21 +102,28 @@ export const ImportComponentPage = ({
}}
>
<Typography variant="body2" paragraph>
There are two ways to register an existing component.
</Typography>
<Typography variant="h6">GitHub Repo</Typography>
<Typography variant="body2" paragraph>
If you already have code in a GitHub repository, enter the full
URL to your repo and a new pull request with a sample Backstage
metadata Entity File (<code>catalog-info.yaml</code>) will be
opened for you.
Ways to register an existing component
</Typography>

{manifestGenerationAvailable(configApi) && (
<React.Fragment>
<Typography variant="h6">GitHub Repo</Typography>
<Typography variant="body2" paragraph>
If you already have code in a GitHub repository, enter the
full URL to your repo and a new pull request with a sample
Backstage metadata Entity File (
<code>catalog-info.yaml</code>) will be opened for you.
</Typography>
</React.Fragment>
)}
<Typography variant="h6">
GitHub Repo &amp; Entity File
{repos.length === 1 ? `${repos[0]} ` : ''} Repository &amp;
Entity File
</Typography>
<Typography variant="body2" paragraph>
If you've already created a Backstage metadata file and put it
in your repo, you can enter the full URL to that Entity File.
If you've already created a {appTitle} metadata file and put it
in your {repositoryString} repository, you can enter the full
URL to that Entity File.
</Typography>
</InfoCard>
</Grid>
Expand All @@ -96,11 +132,14 @@ export const ImportComponentPage = ({
<ImportStepper
steps={[
{
step: 'Insert GitHub repo URL or Entity File URL',
step: manifestGenerationAvailable(configApi)
? 'Insert GitHub repo URL or Entity File URL'
: 'Insert Entity File URL',
content: (
<RegisterComponentForm
nextStep={nextStep}
saveConfig={setConfigFile}
repository={repositoryString}
/>
),
},
Expand Down

0 comments on commit d45a510

Please sign in to comment.