Merge pull request #23687 from backstage/blam/catalog-analyzer
Add a `LocationAnalyzer` when installing the GitHub catalog module
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend-module-github': patch
|
||||
---
|
||||
|
||||
Add location analyzer when installing the module
|
||||
@@ -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)
|
||||
```
|
||||
|
||||
+20
-5
@@ -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<EntityProvider> | 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),
|
||||
);
|
||||
});
|
||||
});
|
||||
+27
-4
@@ -19,26 +19,49 @@ 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,
|
||||
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),
|
||||
@@ -14,4 +14,4 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { catalogModuleGithubEntityProvider as default } from './catalogModuleGithubEntityProvider';
|
||||
export { githubCatalogModule as default } from './githubCatalogModule';
|
||||
|
||||
Reference in New Issue
Block a user