Skip to content

Commit

Permalink
Tech-Insights: Add UrlReaderService to FactRetrieverContext (#2159)
Browse files Browse the repository at this point in the history
* Add UrlReaderService to FactRetrieverContext

Signed-off-by: Artur Bochert <[email protected]>

* Changeset set to major bump.

Signed-off-by: Artur Bochert <[email protected]>

* Update api-reports

Signed-off-by: Artur Bochert <[email protected]>

---------

Signed-off-by: Artur Bochert <[email protected]>
Co-authored-by: Artur Bochert <[email protected]>
  • Loading branch information
famibo and Artur Bochert authored Dec 11, 2024
1 parent 306121a commit c3bbe0f
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions workspaces/tech-insights/.changeset/eighty-brooms-repeat.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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: <
Expand Down Expand Up @@ -127,6 +128,8 @@ export interface TechInsightsOptions<
persistenceContext?: PersistenceContext_2;
// (undocumented)
scheduler: SchedulerService;
// (undocumented)
urlReader: UrlReaderService;
}

// @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('techInsightsPlugin', () => {
httpRouterMock.factory,
mockServices.database.factory(),
mockServices.logger.factory(),
mockServices.urlReader.factory(),
mockServices.rootConfig.factory({
data: {
techInsights: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const techInsightsPlugin = createBackendPlugin({
logger: coreServices.logger,
scheduler: coreServices.scheduler,
auth: coreServices.auth,
urlReader: coreServices.urlReader,
},
async init({
config,
Expand All @@ -110,6 +111,7 @@ export const techInsightsPlugin = createBackendPlugin({
logger,
scheduler,
auth,
urlReader,
}) {
const factRetrievers: FactRetrieverRegistration[] = Object.entries(
addedFactRetrievers,
Expand All @@ -134,6 +136,7 @@ export const techInsightsPlugin = createBackendPlugin({
persistenceContext,
scheduler,
auth,
urlReader,
});

httpRouter.use(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const handlerContext = {
discovery,
logger: mockServices.logger.mock(),
auth: mockServices.auth(),
urlReader: mockServices.urlReader.mock(),
config: ConfigReader.fromConfigs([]),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const handlerContext = {
discovery,
logger: mockServices.logger.mock(),
auth: mockServices.auth(),
urlReader: mockServices.urlReader.mock(),
config: ConfigReader.fromConfigs([]),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const handlerContext = {
discovery,
logger: mockServices.logger.mock(),
auth: mockServices.auth(),
urlReader: mockServices.urlReader.mock(),
config: ConfigReader.fromConfigs([]),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -62,6 +63,7 @@ describe('Tech Insights router tests', () => {
getExternalBaseUrl: (_: string) => Promise.resolve('http://mock.url'),
},
auth: mockServices.auth(),
urlReader,
});

const router = await createRouter({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -61,6 +62,7 @@ describe('buildTechInsightsContext', () => {
config: ConfigReader.fromConfigs([]),
discovery: discoveryMock,
auth: mockServices.auth(),
urlReader,
});
expect(DefaultFactRetrieverRegistry).toHaveBeenCalledTimes(1);
});
Expand All @@ -77,6 +79,7 @@ describe('buildTechInsightsContext', () => {
config: ConfigReader.fromConfigs([]),
discovery: discoveryMock,
auth: mockServices.auth(),
urlReader,
});
expect(DefaultFactRetrieverRegistry).not.toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
DiscoveryService,
LoggerService,
SchedulerService,
UrlReaderService,
} from '@backstage/backend-plugin-api';

/**
Expand Down Expand Up @@ -82,6 +83,7 @@ export interface TechInsightsOptions<
database: DatabaseService;
scheduler: SchedulerService;
auth: AuthService;
urlReader: UrlReaderService;
}

/**
Expand Down Expand Up @@ -125,6 +127,7 @@ export const buildTechInsightsContext = async <
logger,
scheduler,
auth,
urlReader,
} = options;

const buildFactRetrieverRegistry = (): FactRetrieverRegistry => {
Expand Down Expand Up @@ -156,6 +159,7 @@ export const buildTechInsightsContext = async <
discovery,
logger,
auth,
urlReader,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -68,6 +69,7 @@ export type FactRetrieverContext = {
discovery: DiscoveryService;
logger: LoggerService;
auth: AuthService;
urlReader: UrlReaderService;
entityFilter?:
| Record<string, string | symbol | (string | symbol)[]>[]
| Record<string, string | symbol | (string | symbol)[]>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
AuthService,
DiscoveryService,
LoggerService,
UrlReaderService,
} from '@backstage/backend-plugin-api';

/**
Expand Down Expand Up @@ -93,6 +94,7 @@ export type FactRetrieverContext = {
discovery: DiscoveryService;
logger: LoggerService;
auth: AuthService;
urlReader: UrlReaderService;
entityFilter?:
| Record<string, string | symbol | (string | symbol)[]>[]
| Record<string, string | symbol | (string | symbol)[]>;
Expand Down

0 comments on commit c3bbe0f

Please sign in to comment.