diff --git a/plugins/catalog-import/src/api/CatalogImportClient.ts b/plugins/catalog-import/src/api/CatalogImportClient.ts index bc59657cad..1b84fba12f 100644 --- a/plugins/catalog-import/src/api/CatalogImportClient.ts +++ b/plugins/catalog-import/src/api/CatalogImportClient.ts @@ -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({ diff --git a/plugins/catalog-import/src/components/ImportInfoCard/ImportInfoCard.tsx b/plugins/catalog-import/src/components/ImportInfoCard/ImportInfoCard.tsx index 2fab223f20..ef72f79c8a 100644 --- a/plugins/catalog-import/src/components/ImportInfoCard/ImportInfoCard.tsx +++ b/plugins/catalog-import/src/components/ImportInfoCard/ImportInfoCard.tsx @@ -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 ( { Example: https://github.com/backstage/backstage - The wizard discovers all catalog-info.yaml files in the + The wizard discovers all {catalogFilename} files in the repository, previews the entities, and adds them to the {appTitle}{' '} catalog. {catalogImportApi.preparePullRequest && ( If no entities are found, the wizard will prepare a Pull Request - that adds an example catalog-info.yaml and prepares + that adds an example {catalogFilename} and prepares the {appTitle} catalog to load all entities as soon as the Pull Request is merged. diff --git a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/PreviewCatalogInfoComponent.tsx b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/PreviewCatalogInfoComponent.tsx index d0f29c00e2..d97f3a58f6 100644 --- a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/PreviewCatalogInfoComponent.tsx +++ b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/PreviewCatalogInfoComponent.tsx @@ -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 ( {`${trimEnd(repositoryUrl, '/')}/catalog-info.yaml`} + {`${trimEnd(repositoryUrl, '/')}/${catalogFilename}`} } /> diff --git a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx index 077d99c4ba..d511294b61 100644 --- a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx +++ b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx @@ -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(); + const catalogFilename = + configApi.getOptionalString('catalog.import.entityFilename') ?? + 'catalog-info.yaml'; + const { loading: prDefaultsLoading, value: prDefaults, @@ -193,7 +198,7 @@ export const StepPrepareCreatePullRequest = ({ <> You entered a link to a {analyzeResult.integrationType} repository but a{' '} - catalog-info.yaml could not be found. Use this form to open + {catalogFilename} could not be found. Use this form to open a Pull Request that creates one.