Merge branch 'backstage:master' into master

This commit is contained in:
matteosilv
2023-02-20 16:25:52 +01:00
committed by GitHub
6 changed files with 740 additions and 680 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': patch
---
throw error from catalog:fetch scaffolder action when entity is null and optional is false
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-tech-insights-backend': patch
---
Add DB index to improve latency of latest fact query
@@ -90,7 +90,7 @@ describe('catalog:fetch', () => {
expect(mockContext.output).toHaveBeenCalledWith('entity', null);
});
it('should throw error if entity not in catalog and optional is false', async () => {
it('should throw error if entity fetch fails from catalog and optional is false', async () => {
getEntityByRef.mockImplementationOnce(() => {
throw new Error('Not found');
});
@@ -109,4 +109,22 @@ describe('catalog:fetch', () => {
});
expect(mockContext.output).not.toHaveBeenCalled();
});
it('should throw error if entity not in catalog and optional is false', async () => {
getEntityByRef.mockReturnValueOnce(null);
await expect(
action.handler({
...mockContext,
input: {
entityRef: 'component:default/test',
},
}),
).rejects.toThrow('Entity component:default/test not found');
expect(getEntityByRef).toHaveBeenCalledWith('component:default/test', {
token: 'secret',
});
expect(mockContext.output).not.toHaveBeenCalled();
});
});
@@ -93,6 +93,11 @@ export function createFetchCatalogEntityAction(options: {
throw e;
}
}
if (!entity && !optional) {
throw new Error(`Entity ${entityRef} not found`);
}
ctx.output('entity', entity ?? null);
},
});
@@ -0,0 +1,36 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const indexName = 'fact_id_entity_timestamp_idx';
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async knex => {
await knex.schema.alterTable('facts', table => {
table.index(['id', 'entity', 'timestamp'], indexName);
});
};
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async knex => {
await knex.schema.alterTable('facts', table => {
table.dropIndex(indexName);
});
};
+670 -679
View File
File diff suppressed because it is too large Load Diff