From 19dadcb17391ad723cb3816640e7de8e9955cceb Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 18 Mar 2024 16:45:18 +0100 Subject: [PATCH 1/4] feat: add location analyzer to github module and refactor Signed-off-by: blam --- ...er.test.ts => githubCatalogModule.test.ts} | 25 ++++++++++++--- ...tityProvider.ts => githubCatalogModule.ts} | 32 ++++++++++++++++--- .../src/module/index.ts | 2 +- 3 files changed, 49 insertions(+), 10 deletions(-) rename plugins/catalog-backend-module-github/src/module/{catalogModuleGithubEntityProvider.test.ts => githubCatalogModule.test.ts} (75%) rename plugins/catalog-backend-module-github/src/module/{catalogModuleGithubEntityProvider.ts => githubCatalogModule.ts} (64%) diff --git a/plugins/catalog-backend-module-github/src/module/catalogModuleGithubEntityProvider.test.ts b/plugins/catalog-backend-module-github/src/module/githubCatalogModule.test.ts similarity index 75% rename from plugins/catalog-backend-module-github/src/module/catalogModuleGithubEntityProvider.test.ts rename to plugins/catalog-backend-module-github/src/module/githubCatalogModule.test.ts index cb38be1a5d..0f466fefb7 100644 --- a/plugins/catalog-backend-module-github/src/module/catalogModuleGithubEntityProvider.test.ts +++ b/plugins/catalog-backend-module-github/src/module/githubCatalogModule.test.ts @@ -17,11 +17,15 @@ import { TaskScheduleDefinition } from '@backstage/backend-tasks'; import { mockServices, startTestBackend } from '@backstage/backend-test-utils'; import { EntityProvider } from '@backstage/plugin-catalog-node'; -import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha'; +import { + catalogAnalysisExtensionPoint, + catalogProcessingExtensionPoint, +} from '@backstage/plugin-catalog-node/alpha'; import { Duration } from 'luxon'; -import { catalogModuleGithubEntityProvider } from './catalogModuleGithubEntityProvider'; +import { githubCatalogModule } from './githubCatalogModule'; +import { GithubLocationAnalyzer } from '../analyzers/GithubLocationAnalyzer'; -describe('catalogModuleGithubEntityProvider', () => { +describe('githubCatalogModule', () => { it('should register provider at the catalog extension point', async () => { let addedProviders: Array | undefined; let usedSchedule: TaskScheduleDefinition | undefined; @@ -31,6 +35,11 @@ describe('catalogModuleGithubEntityProvider', () => { addedProviders = providers; }, }; + + const analysisExtensionPoint = { + addLocationAnalyzer: jest.fn(), + }; + const runner = jest.fn(); const scheduler = mockServices.scheduler.mock({ createScheduledTaskRunner(schedule) { @@ -54,9 +63,12 @@ describe('catalogModuleGithubEntityProvider', () => { }; await startTestBackend({ - extensionPoints: [[catalogProcessingExtensionPoint, extensionPoint]], + extensionPoints: [ + [catalogProcessingExtensionPoint, extensionPoint], + [catalogAnalysisExtensionPoint, analysisExtensionPoint], + ], features: [ - catalogModuleGithubEntityProvider(), + githubCatalogModule(), mockServices.rootConfig.factory({ data: config }), scheduler.factory, ], @@ -69,5 +81,8 @@ describe('catalogModuleGithubEntityProvider', () => { 'github-provider:default', ); expect(runner).not.toHaveBeenCalled(); + expect(analysisExtensionPoint.addLocationAnalyzer).toHaveBeenCalledWith( + expect.any(GithubLocationAnalyzer), + ); }); }); diff --git a/plugins/catalog-backend-module-github/src/module/catalogModuleGithubEntityProvider.ts b/plugins/catalog-backend-module-github/src/module/githubCatalogModule.ts similarity index 64% rename from plugins/catalog-backend-module-github/src/module/catalogModuleGithubEntityProvider.ts rename to plugins/catalog-backend-module-github/src/module/githubCatalogModule.ts index bfa8cf2a4e..cb9d1c43f6 100644 --- a/plugins/catalog-backend-module-github/src/module/catalogModuleGithubEntityProvider.ts +++ b/plugins/catalog-backend-module-github/src/module/githubCatalogModule.ts @@ -19,26 +19,50 @@ import { coreServices, } from '@backstage/backend-plugin-api'; import { loggerToWinstonLogger } from '@backstage/backend-common'; -import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha'; +import { + catalogAnalysisExtensionPoint, + catalogProcessingExtensionPoint, +} from '@backstage/plugin-catalog-node/alpha'; import { GithubEntityProvider } from '../providers/GithubEntityProvider'; +import { GithubLocationAnalyzer } from '../analyzers/GithubLocationAnalyzer'; /** * Registers the `GithubEntityProvider` with the catalog processing extension point. * * @alpha */ -export const catalogModuleGithubEntityProvider = createBackendModule({ +export const githubCatalogModule = createBackendModule({ pluginId: 'catalog', - moduleId: 'github-entity-provider', + moduleId: 'github', register(env) { env.registerInit({ deps: { catalog: catalogProcessingExtensionPoint, + analyzers: catalogAnalysisExtensionPoint, + auth: coreServices.auth, + tokenManager: coreServices.tokenManager, + discovery: coreServices.discovery, config: coreServices.rootConfig, logger: coreServices.logger, scheduler: coreServices.scheduler, }, - async init({ catalog, config, logger, scheduler }) { + async init({ + catalog, + config, + logger, + scheduler, + analyzers, + discovery, + auth, + }) { + analyzers.addLocationAnalyzer( + new GithubLocationAnalyzer({ + discovery, + config, + auth, + }), + ); + catalog.addEntityProvider( GithubEntityProvider.fromConfig(config, { logger: loggerToWinstonLogger(logger), diff --git a/plugins/catalog-backend-module-github/src/module/index.ts b/plugins/catalog-backend-module-github/src/module/index.ts index 9c9331763c..02b377a4b2 100644 --- a/plugins/catalog-backend-module-github/src/module/index.ts +++ b/plugins/catalog-backend-module-github/src/module/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export { catalogModuleGithubEntityProvider as default } from './catalogModuleGithubEntityProvider'; +export { githubCatalogModule as default } from './githubCatalogModule'; From 9eab52ae2b510c7a71265ec585b0f071597a532b Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 18 Mar 2024 16:46:34 +0100 Subject: [PATCH 2/4] chore: changeset Signed-off-by: blam --- .changeset/tall-jeans-buy.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tall-jeans-buy.md diff --git a/.changeset/tall-jeans-buy.md b/.changeset/tall-jeans-buy.md new file mode 100644 index 0000000000..6892c886b0 --- /dev/null +++ b/.changeset/tall-jeans-buy.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-github': patch +--- + +Add location analyzer when installing the module From b63b3b8514899adc9d72054e7bcbe2d2950af752 Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 18 Mar 2024 17:13:12 +0100 Subject: [PATCH 3/4] chore: fixing api-reports Signed-off-by: blam --- plugins/catalog-backend-module-github/api-report-alpha.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-backend-module-github/api-report-alpha.md b/plugins/catalog-backend-module-github/api-report-alpha.md index cd5344f728..ca3a7b1978 100644 --- a/plugins/catalog-backend-module-github/api-report-alpha.md +++ b/plugins/catalog-backend-module-github/api-report-alpha.md @@ -6,8 +6,8 @@ import { BackendFeature } from '@backstage/backend-plugin-api'; // @alpha -const catalogModuleGithubEntityProvider: () => BackendFeature; -export default catalogModuleGithubEntityProvider; +const githubCatalogModule: () => BackendFeature; +export default githubCatalogModule; // (No @packageDocumentation comment for this package) ``` From f729291a05f08b28ac3981c80dddd31bb896010d Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 18 Mar 2024 17:14:36 +0100 Subject: [PATCH 4/4] chore: remove token mgr Signed-off-by: blam --- .../src/module/githubCatalogModule.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/catalog-backend-module-github/src/module/githubCatalogModule.ts b/plugins/catalog-backend-module-github/src/module/githubCatalogModule.ts index cb9d1c43f6..55a1b7f34d 100644 --- a/plugins/catalog-backend-module-github/src/module/githubCatalogModule.ts +++ b/plugins/catalog-backend-module-github/src/module/githubCatalogModule.ts @@ -40,7 +40,6 @@ export const githubCatalogModule = createBackendModule({ catalog: catalogProcessingExtensionPoint, analyzers: catalogAnalysisExtensionPoint, auth: coreServices.auth, - tokenManager: coreServices.tokenManager, discovery: coreServices.discovery, config: coreServices.rootConfig, logger: coreServices.logger,