feat(catalog-import): read catalog filename from app config
Signed-off-by: Mikko Korhonen <mikko.korhonen@gmail.com>
This commit is contained in:
@@ -87,13 +87,17 @@ export class CatalogImportClient implements CatalogImportApi {
|
||||
const ghConfig = getGithubIntegrationConfig(this.scmIntegrationsApi, url);
|
||||
if (!ghConfig) {
|
||||
const other = this.scmIntegrationsApi.byUrl(url);
|
||||
const catalogFilename =
|
||||
this.configApi.getOptionalString('catalog.import.entityFilename') ??
|
||||
'catalog-info.yaml';
|
||||
|
||||
if (other) {
|
||||
throw new Error(
|
||||
`The ${other.title} integration only supports full URLs to catalog-info.yaml files. Did you try to pass in the URL of a directory instead?`,
|
||||
`The ${other.title} integration only supports full URLs to ${catalogFilename} files. Did you try to pass in the URL of a directory instead?`,
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
'This URL was not recognized as a valid GitHub URL because there was no configured integration that matched the given host name. You could try to paste the full URL to a catalog-info.yaml file instead.',
|
||||
`This URL was not recognized as a valid GitHub URL because there was no configured integration that matched the given host name. You could try to paste the full URL to a ${catalogFilename} file instead.`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -127,9 +131,12 @@ export class CatalogImportClient implements CatalogImportApi {
|
||||
const appTitle =
|
||||
this.configApi.getOptionalString('app.title') ?? 'Backstage';
|
||||
const appBaseUrl = this.configApi.getString('app.baseUrl');
|
||||
const catalogFilename =
|
||||
this.configApi.getOptionalString('catalog.import.entityFilename') ??
|
||||
'catalog-info.yaml';
|
||||
|
||||
return {
|
||||
title: 'Add catalog-info.yaml config file',
|
||||
title: `Add ${catalogFilename} config file`,
|
||||
body: `This pull request adds a **Backstage entity metadata file** \
|
||||
to this repository so that the component can be added to the \
|
||||
[${appTitle} software catalog](${appBaseUrl}).\n\nAfter this pull request is merged, \
|
||||
@@ -221,8 +228,10 @@ the component will become available.\n\nFor more information, read an \
|
||||
auth: token,
|
||||
baseUrl: githubIntegrationConfig.apiBaseUrl,
|
||||
});
|
||||
const catalogFileName = 'catalog-info.yaml';
|
||||
const query = `repo:${owner}/${repo}+filename:${catalogFileName}`;
|
||||
const catalogFilename =
|
||||
this.configApi.getOptionalString('catalog.import.entityFilename') ??
|
||||
'catalog-info.yaml';
|
||||
const query = `repo:${owner}/${repo}+filename:${catalogFilename}`;
|
||||
|
||||
const searchResult = await octo.search.code({ q: query }).catch(e => {
|
||||
throw new Error(
|
||||
@@ -295,7 +304,9 @@ the component will become available.\n\nFor more information, read an \
|
||||
});
|
||||
|
||||
const branchName = 'backstage-integration';
|
||||
const fileName = 'catalog-info.yaml';
|
||||
const fileName =
|
||||
this.configApi.getOptionalString('catalog.import.entityFilename') ??
|
||||
'catalog-info.yaml';
|
||||
|
||||
const repoData = await octo.repos
|
||||
.get({
|
||||
|
||||
@@ -28,6 +28,10 @@ export const ImportInfoCard = () => {
|
||||
const integrations = configApi.getConfig('integrations');
|
||||
const hasGithubIntegration = integrations.has('github');
|
||||
|
||||
const catalogFilename =
|
||||
configApi.getOptionalString('catalog.import.entityFilename') ??
|
||||
'catalog-info.yaml';
|
||||
|
||||
return (
|
||||
<InfoCard
|
||||
title="Register an existing component"
|
||||
@@ -60,14 +64,14 @@ export const ImportInfoCard = () => {
|
||||
Example: <code>https://github.com/backstage/backstage</code>
|
||||
</Typography>
|
||||
<Typography variant="body2" paragraph>
|
||||
The wizard discovers all <code>catalog-info.yaml</code> files in the
|
||||
The wizard discovers all <code>{catalogFilename}</code> files in the
|
||||
repository, previews the entities, and adds them to the {appTitle}{' '}
|
||||
catalog.
|
||||
</Typography>
|
||||
{catalogImportApi.preparePullRequest && (
|
||||
<Typography variant="body2" paragraph>
|
||||
If no entities are found, the wizard will prepare a Pull Request
|
||||
that adds an example <code>catalog-info.yaml</code> and prepares
|
||||
that adds an example <code>{catalogFilename}</code> and prepares
|
||||
the {appTitle} catalog to load all entities as soon as the Pull
|
||||
Request is merged.
|
||||
</Typography>
|
||||
|
||||
+7
-1
@@ -19,6 +19,7 @@ import { Card, CardContent, CardHeader } from '@material-ui/core';
|
||||
import React from 'react';
|
||||
import YAML from 'yaml';
|
||||
import { CodeSnippet } from '@backstage/core-components';
|
||||
import { configApiRef, useApi } from '@backstage/core-plugin-api';
|
||||
import { trimEnd } from 'lodash';
|
||||
|
||||
type Props = {
|
||||
@@ -32,11 +33,16 @@ export const PreviewCatalogInfoComponent = ({
|
||||
entities,
|
||||
classes,
|
||||
}: Props) => {
|
||||
const configApi = useApi(configApiRef);
|
||||
const catalogFilename =
|
||||
configApi.getOptionalString('catalog.import.entityFilename') ??
|
||||
'catalog-info.yaml';
|
||||
|
||||
return (
|
||||
<Card variant="outlined" className={classes?.card}>
|
||||
<CardHeader
|
||||
title={
|
||||
<code>{`${trimEnd(repositoryUrl, '/')}/catalog-info.yaml`}</code>
|
||||
<code>{`${trimEnd(repositoryUrl, '/')}/${catalogFilename}`}</code>
|
||||
}
|
||||
/>
|
||||
|
||||
|
||||
+7
-2
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { errorApiRef, useApi } from '@backstage/core-plugin-api';
|
||||
import { configApiRef, errorApiRef, useApi } from '@backstage/core-plugin-api';
|
||||
import { assertError } from '@backstage/errors';
|
||||
import {
|
||||
catalogApiRef,
|
||||
@@ -102,10 +102,15 @@ export const StepPrepareCreatePullRequest = ({
|
||||
const catalogApi = useApi(catalogApiRef);
|
||||
const catalogImportApi = useApi(catalogImportApiRef);
|
||||
const errorApi = useApi(errorApiRef);
|
||||
const configApi = useApi(configApiRef);
|
||||
|
||||
const [submitted, setSubmitted] = useState(false);
|
||||
const [error, setError] = useState<string>();
|
||||
|
||||
const catalogFilename =
|
||||
configApi.getOptionalString('catalog.import.entityFilename') ??
|
||||
'catalog-info.yaml';
|
||||
|
||||
const {
|
||||
loading: prDefaultsLoading,
|
||||
value: prDefaults,
|
||||
@@ -193,7 +198,7 @@ export const StepPrepareCreatePullRequest = ({
|
||||
<>
|
||||
<Typography>
|
||||
You entered a link to a {analyzeResult.integrationType} repository but a{' '}
|
||||
<code>catalog-info.yaml</code> could not be found. Use this form to open
|
||||
<code>{catalogFilename}</code> could not be found. Use this form to open
|
||||
a Pull Request that creates one.
|
||||
</Typography>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user