catalog-backend-module-github: add initial module export for provider

Co-authored-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: blam <ben@blam.sh>
Co-authored-by: Johan Haals <johan.haals@gmail.com>
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-08-15 13:53:11 +02:00
parent f3bdd15ab3
commit 7ac3306e27
4 changed files with 85 additions and 0 deletions
@@ -3,6 +3,7 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { BackendFeature } from '@backstage/backend-plugin-api';
import { CatalogProcessor } from '@backstage/plugin-catalog-backend';
import { CatalogProcessorEmit } from '@backstage/plugin-catalog-backend';
import { Config } from '@backstage/config';
@@ -14,6 +15,7 @@ import { LocationSpec } from '@backstage/plugin-catalog-backend';
import { Logger } from 'winston';
import { ScmIntegrationRegistry } from '@backstage/integration';
import { TaskRunner } from '@backstage/backend-tasks';
import { TaskScheduleDefinition } from '@backstage/backend-tasks';
// @public
export class GithubDiscoveryProcessor implements CatalogProcessor {
@@ -58,6 +60,16 @@ export class GitHubEntityProvider implements EntityProvider {
refresh(logger: Logger): Promise<void>;
}
// @alpha
export const githubEntityProviderCatalogModule: (
options?: GithubEntityProviderCatalogModuleOptions | undefined,
) => BackendFeature;
// @alpha
export type GithubEntityProviderCatalogModuleOptions = {
schedule?: TaskScheduleDefinition;
};
// @public
export type GithubMultiOrgConfig = Array<{
name: string;
@@ -35,11 +35,13 @@
"dependencies": {
"@backstage/backend-common": "^0.15.0",
"@backstage/backend-tasks": "^0.3.4",
"@backstage/backend-plugin-api": "^0.1.1",
"@backstage/catalog-model": "^1.1.0",
"@backstage/config": "^1.0.1",
"@backstage/errors": "^1.1.0",
"@backstage/integration": "^1.3.0",
"@backstage/plugin-catalog-backend": "^1.3.1",
"@backstage/plugin-catalog-node": "^1.0.1",
"@backstage/types": "^1.0.0",
"@octokit/graphql": "^5.0.0",
"lodash": "^4.17.21",
@@ -27,3 +27,5 @@ export { GitHubEntityProvider } from './providers/GitHubEntityProvider';
export { GitHubOrgEntityProvider } from './providers/GitHubOrgEntityProvider';
export type { GitHubOrgEntityProviderOptions } from './providers/GitHubOrgEntityProvider';
export type { GithubMultiOrgConfig } from './lib';
export { githubEntityProviderCatalogModule } from './module';
export type { GithubEntityProviderCatalogModuleOptions } from './module';
@@ -0,0 +1,69 @@
/*
* Copyright 2022 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
createBackendModule,
loggerToWinstonLogger,
configServiceRef,
loggerServiceRef,
schedulerServiceRef,
} from '@backstage/backend-plugin-api';
import { TaskScheduleDefinition } from '@backstage/backend-tasks';
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node';
import { GitHubEntityProvider } from './providers/GitHubEntityProvider';
/**
* Options for {@link githubEntityProviderCatalogModule}.
*
* @alpha
*/
export type GithubEntityProviderCatalogModuleOptions = {
schedule?: TaskScheduleDefinition;
};
/**
* Registers the GitHubEntityProvider with the catalog processing extension point.
*
* @alpha
*/
export const githubEntityProviderCatalogModule = createBackendModule({
pluginId: 'catalog',
moduleId: 'github-entity-provider',
register(env, options?: GithubEntityProviderCatalogModuleOptions) {
env.registerInit({
deps: {
config: configServiceRef,
catalog: catalogProcessingExtensionPoint,
logger: loggerServiceRef,
scheduler: schedulerServiceRef,
},
async init({ config, catalog, logger, scheduler }) {
const scheduleDef = options?.schedule ?? {
frequency: { seconds: 600 },
timeout: { seconds: 900 },
initialDelay: { seconds: 3 },
};
catalog.addEntityProvider(
GitHubEntityProvider.fromConfig(config, {
logger: loggerToWinstonLogger(logger),
schedule: scheduler.createScheduledTaskRunner(scheduleDef),
}),
);
},
});
},
});