From c3bbe0f7baba343b118090c35016081baa4a5380 Mon Sep 17 00:00:00 2001 From: Artur Bochert Date: Wed, 11 Dec 2024 11:03:56 +0100 Subject: [PATCH] Tech-Insights: Add UrlReaderService to FactRetrieverContext (#2159) * Add UrlReaderService to FactRetrieverContext Signed-off-by: Artur Bochert * Changeset set to major bump. Signed-off-by: Artur Bochert * Update api-reports Signed-off-by: Artur Bochert --------- Signed-off-by: Artur Bochert Co-authored-by: Artur Bochert --- workspaces/tech-insights/.changeset/eighty-brooms-repeat.md | 6 ++++++ .../plugins/tech-insights-backend/report.api.md | 3 +++ .../plugins/tech-insights-backend/src/plugin/plugin.test.ts | 1 + .../plugins/tech-insights-backend/src/plugin/plugin.ts | 3 +++ .../src/service/fact/FactRetrieverEngine.test.ts | 2 ++ .../fact/factRetrievers/entityMetadataFactRetriever.test.ts | 1 + .../factRetrievers/entityOwnershipFactRetriever.test.ts | 1 + .../fact/factRetrievers/techdocsFactRetriever.test.ts | 1 + .../tech-insights-backend/src/service/router.test.ts | 2 ++ .../src/service/techInsightsContextBuilder.test.ts | 3 +++ .../src/service/techInsightsContextBuilder.ts | 4 ++++ .../tech-insights/plugins/tech-insights-node/report.api.md | 2 ++ .../tech-insights/plugins/tech-insights-node/src/facts.ts | 2 ++ 13 files changed, 31 insertions(+) create mode 100644 workspaces/tech-insights/.changeset/eighty-brooms-repeat.md diff --git a/workspaces/tech-insights/.changeset/eighty-brooms-repeat.md b/workspaces/tech-insights/.changeset/eighty-brooms-repeat.md new file mode 100644 index 0000000000..e2e9856f3a --- /dev/null +++ b/workspaces/tech-insights/.changeset/eighty-brooms-repeat.md @@ -0,0 +1,6 @@ +--- +'@backstage-community/plugin-tech-insights-backend': major +'@backstage-community/plugin-tech-insights-node': major +--- + +In order to use UrlReaderService in fact retrievers, UrlReaderService has been added to FactRetrieverContext. diff --git a/workspaces/tech-insights/plugins/tech-insights-backend/report.api.md b/workspaces/tech-insights/plugins/tech-insights-backend/report.api.md index c442522845..9f7fdeab8a 100644 --- a/workspaces/tech-insights/plugins/tech-insights-backend/report.api.md +++ b/workspaces/tech-insights/plugins/tech-insights-backend/report.api.md @@ -22,6 +22,7 @@ import { LoggerService } from '@backstage/backend-plugin-api'; import { PersistenceContext as PersistenceContext_2 } from '@backstage-community/plugin-tech-insights-node'; import { SchedulerService } from '@backstage/backend-plugin-api'; import { TechInsightCheck } from '@backstage-community/plugin-tech-insights-node'; +import { UrlReaderService } from '@backstage/backend-plugin-api'; // @public export const buildTechInsightsContext: < @@ -127,6 +128,8 @@ export interface TechInsightsOptions< persistenceContext?: PersistenceContext_2; // (undocumented) scheduler: SchedulerService; + // (undocumented) + urlReader: UrlReaderService; } // @public diff --git a/workspaces/tech-insights/plugins/tech-insights-backend/src/plugin/plugin.test.ts b/workspaces/tech-insights/plugins/tech-insights-backend/src/plugin/plugin.test.ts index 636837cfdb..ef16aa621f 100644 --- a/workspaces/tech-insights/plugins/tech-insights-backend/src/plugin/plugin.test.ts +++ b/workspaces/tech-insights/plugins/tech-insights-backend/src/plugin/plugin.test.ts @@ -28,6 +28,7 @@ describe('techInsightsPlugin', () => { httpRouterMock.factory, mockServices.database.factory(), mockServices.logger.factory(), + mockServices.urlReader.factory(), mockServices.rootConfig.factory({ data: { techInsights: { diff --git a/workspaces/tech-insights/plugins/tech-insights-backend/src/plugin/plugin.ts b/workspaces/tech-insights/plugins/tech-insights-backend/src/plugin/plugin.ts index a355b374ab..c08210dbd6 100644 --- a/workspaces/tech-insights/plugins/tech-insights-backend/src/plugin/plugin.ts +++ b/workspaces/tech-insights/plugins/tech-insights-backend/src/plugin/plugin.ts @@ -101,6 +101,7 @@ export const techInsightsPlugin = createBackendPlugin({ logger: coreServices.logger, scheduler: coreServices.scheduler, auth: coreServices.auth, + urlReader: coreServices.urlReader, }, async init({ config, @@ -110,6 +111,7 @@ export const techInsightsPlugin = createBackendPlugin({ logger, scheduler, auth, + urlReader, }) { const factRetrievers: FactRetrieverRegistration[] = Object.entries( addedFactRetrievers, @@ -134,6 +136,7 @@ export const techInsightsPlugin = createBackendPlugin({ persistenceContext, scheduler, auth, + urlReader, }); httpRouter.use( diff --git a/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts b/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts index 1dae618dc9..bf14df349a 100644 --- a/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts +++ b/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts @@ -135,6 +135,7 @@ describe('FactRetrieverEngine', () => { }; const manager = databaseManager as DatabaseManager; const logger = mockServices.logger.mock(); + const urlReader = mockServices.urlReader.mock(); const lifecycle = mockServices.lifecycle.mock(); const database = manager.forPlugin('tech-insights', { logger, lifecycle }); const scheduler = DefaultSchedulerService.create({ database, logger }); @@ -143,6 +144,7 @@ describe('FactRetrieverEngine', () => { logger, config: ConfigReader.fromConfigs([]), auth: mockServices.auth(), + urlReader, discovery: { getBaseUrl: (_: string) => Promise.resolve('http://mock.url'), getExternalBaseUrl: (_: string) => Promise.resolve('http://mock.url'), diff --git a/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.test.ts b/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.test.ts index b33b605532..6b6d9a2ec7 100644 --- a/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.test.ts +++ b/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.test.ts @@ -102,6 +102,7 @@ const handlerContext = { discovery, logger: mockServices.logger.mock(), auth: mockServices.auth(), + urlReader: mockServices.urlReader.mock(), config: ConfigReader.fromConfigs([]), }; diff --git a/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.test.ts b/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.test.ts index 0b45f24ef8..0af95903b0 100644 --- a/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.test.ts +++ b/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.test.ts @@ -102,6 +102,7 @@ const handlerContext = { discovery, logger: mockServices.logger.mock(), auth: mockServices.auth(), + urlReader: mockServices.urlReader.mock(), config: ConfigReader.fromConfigs([]), }; diff --git a/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.test.ts b/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.test.ts index b808c3cda9..a493c1e3de 100644 --- a/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.test.ts +++ b/workspaces/tech-insights/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.test.ts @@ -103,6 +103,7 @@ const handlerContext = { discovery, logger: mockServices.logger.mock(), auth: mockServices.auth(), + urlReader: mockServices.urlReader.mock(), config: ConfigReader.fromConfigs([]), }; diff --git a/workspaces/tech-insights/plugins/tech-insights-backend/src/service/router.test.ts b/workspaces/tech-insights/plugins/tech-insights-backend/src/service/router.test.ts index e673156b15..d11a787800 100644 --- a/workspaces/tech-insights/plugins/tech-insights-backend/src/service/router.test.ts +++ b/workspaces/tech-insights/plugins/tech-insights-backend/src/service/router.test.ts @@ -51,6 +51,7 @@ describe('Tech Insights router tests', () => { migrations: { skip: true }, }); const logger = mockServices.logger.mock(); + const urlReader = mockServices.urlReader.mock(); const techInsightsContext = await buildTechInsightsContext({ database, logger, @@ -62,6 +63,7 @@ describe('Tech Insights router tests', () => { getExternalBaseUrl: (_: string) => Promise.resolve('http://mock.url'), }, auth: mockServices.auth(), + urlReader, }); const router = await createRouter({ diff --git a/workspaces/tech-insights/plugins/tech-insights-backend/src/service/techInsightsContextBuilder.test.ts b/workspaces/tech-insights/plugins/tech-insights-backend/src/service/techInsightsContextBuilder.test.ts index 94b7626daf..6ce2aa3ed9 100644 --- a/workspaces/tech-insights/plugins/tech-insights-backend/src/service/techInsightsContextBuilder.test.ts +++ b/workspaces/tech-insights/plugins/tech-insights-backend/src/service/techInsightsContextBuilder.test.ts @@ -33,6 +33,7 @@ jest.mock('./fact/FactRetrieverEngine', () => ({ describe('buildTechInsightsContext', () => { const logger = mockServices.logger.mock(); + const urlReader = mockServices.urlReader.mock(); const database: DatabaseService = { getClient: () => { return Promise.resolve({ @@ -61,6 +62,7 @@ describe('buildTechInsightsContext', () => { config: ConfigReader.fromConfigs([]), discovery: discoveryMock, auth: mockServices.auth(), + urlReader, }); expect(DefaultFactRetrieverRegistry).toHaveBeenCalledTimes(1); }); @@ -77,6 +79,7 @@ describe('buildTechInsightsContext', () => { config: ConfigReader.fromConfigs([]), discovery: discoveryMock, auth: mockServices.auth(), + urlReader, }); expect(DefaultFactRetrieverRegistry).not.toHaveBeenCalled(); }); diff --git a/workspaces/tech-insights/plugins/tech-insights-backend/src/service/techInsightsContextBuilder.ts b/workspaces/tech-insights/plugins/tech-insights-backend/src/service/techInsightsContextBuilder.ts index ef9970b3ea..f156dc9611 100644 --- a/workspaces/tech-insights/plugins/tech-insights-backend/src/service/techInsightsContextBuilder.ts +++ b/workspaces/tech-insights/plugins/tech-insights-backend/src/service/techInsightsContextBuilder.ts @@ -36,6 +36,7 @@ import { DiscoveryService, LoggerService, SchedulerService, + UrlReaderService, } from '@backstage/backend-plugin-api'; /** @@ -82,6 +83,7 @@ export interface TechInsightsOptions< database: DatabaseService; scheduler: SchedulerService; auth: AuthService; + urlReader: UrlReaderService; } /** @@ -125,6 +127,7 @@ export const buildTechInsightsContext = async < logger, scheduler, auth, + urlReader, } = options; const buildFactRetrieverRegistry = (): FactRetrieverRegistry => { @@ -156,6 +159,7 @@ export const buildTechInsightsContext = async < discovery, logger, auth, + urlReader, }, }); diff --git a/workspaces/tech-insights/plugins/tech-insights-node/report.api.md b/workspaces/tech-insights/plugins/tech-insights-node/report.api.md index 354d669f6c..2d2b83e6d1 100644 --- a/workspaces/tech-insights/plugins/tech-insights-node/report.api.md +++ b/workspaces/tech-insights/plugins/tech-insights-node/report.api.md @@ -17,6 +17,7 @@ import { FactSchema } from '@backstage-community/plugin-tech-insights-common'; import { HumanDuration } from '@backstage/types'; import { JsonValue } from '@backstage/types'; import { LoggerService } from '@backstage/backend-plugin-api'; +import { UrlReaderService } from '@backstage/backend-plugin-api'; // @public export type CheckValidationResponse = { @@ -68,6 +69,7 @@ export type FactRetrieverContext = { discovery: DiscoveryService; logger: LoggerService; auth: AuthService; + urlReader: UrlReaderService; entityFilter?: | Record[] | Record; diff --git a/workspaces/tech-insights/plugins/tech-insights-node/src/facts.ts b/workspaces/tech-insights/plugins/tech-insights-node/src/facts.ts index 401f23cc66..b238873823 100644 --- a/workspaces/tech-insights/plugins/tech-insights-node/src/facts.ts +++ b/workspaces/tech-insights/plugins/tech-insights-node/src/facts.ts @@ -22,6 +22,7 @@ import { AuthService, DiscoveryService, LoggerService, + UrlReaderService, } from '@backstage/backend-plugin-api'; /** @@ -93,6 +94,7 @@ export type FactRetrieverContext = { discovery: DiscoveryService; logger: LoggerService; auth: AuthService; + urlReader: UrlReaderService; entityFilter?: | Record[] | Record;