Merge pull request #3008 from RoadieHQ/mcalus3/enable-pending-locations-for-repo-importing

Mcalus3/enable pending locations for repo importing
This commit is contained in:
Fredrik Adelöw
2020-10-22 15:33:45 +02:00
committed by GitHub
5 changed files with 18 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/catalog-model': minor
---
Enable adding locations for config files that does not yet exist by adding a flag to api request
@@ -17,6 +17,10 @@
export type LocationSpec = {
type: string;
target: string;
// When using repo importer plugin, location is being created before the component yaml file is merged to the main branch.
// This flag is then set to indicate that the file can be not present.
// default value: 'required'.
presence?: 'optional' | 'required';
};
export type Location = {
@@ -21,6 +21,7 @@ export const locationSpecSchema = yup
.object<LocationSpec>({
type: yup.string().required(),
target: yup.string().required(),
presence: yup.string(),
})
.noUnknown()
.required();
@@ -79,7 +79,7 @@ export class HigherOrderOperations implements HigherOrderOperation {
// Read the location fully, bailing on any errors
const readerOutput = await this.locationReader.read(spec);
if (readerOutput.errors.length) {
if (!(spec.presence === 'optional') && readerOutput.errors.length) {
const item = readerOutput.errors[0];
throw new InputError(
`Failed to read location ${item.location.type}:${item.location.target}, ${item.error}`,
+7 -1
View File
@@ -109,9 +109,15 @@ export class CatalogClient implements CatalogApi {
const { location, entities } = await response.json();
if (!location || entities.length === 0)
if (!location) {
throw new Error(`Location wasn't added: ${target}`);
}
if (entities.length === 0) {
throw new Error(
`Location was added but has no entities specified yet: ${target}`,
);
}
return {
location,
entities,