feat: add location analyzer to github module and refactor
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
+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),
|
||||
);
|
||||
});
|
||||
});
|
||||
+28
-4
@@ -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),
|
||||
@@ -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