diff --git a/.changeset/fuzzy-dolls-shake.md b/.changeset/fuzzy-dolls-shake.md index 35ebcf6103..2d290a3bf3 100644 --- a/.changeset/fuzzy-dolls-shake.md +++ b/.changeset/fuzzy-dolls-shake.md @@ -9,10 +9,10 @@ Add the following to your `CatalogBuilder` to have the repo URL ingestion workin ```ts // catalog.ts -import { GitHubLocationAnalyzer } from '@backstage/plugin-catalog-backend-module-github'; +import { GithubLocationAnalyzer } from '@backstage/plugin-catalog-backend-module-github'; ... builder.addLocationAnalyzers( - new GitHubLocationAnalyzer({ + new GithubLocationAnalyzer({ discovery: env.discovery, config: env.config, }), diff --git a/.changeset/moody-carrots-shout.md b/.changeset/moody-carrots-shout.md index 486590e0ba..6e15fe3ff5 100644 --- a/.changeset/moody-carrots-shout.md +++ b/.changeset/moody-carrots-shout.md @@ -2,4 +2,4 @@ '@backstage/plugin-catalog-backend-module-github': patch --- -Added `GitHubLocationAnalyzer`. This can be used to add to the `CatalogBuilder`. When added this will be used by `RepoLocationAnalyzer` to figure out if the given URL that you are trying to import from the /catalog-import page already contains catalog-info.yaml files. +Added `GithubLocationAnalyzer`. This can be used to add to the `CatalogBuilder`. When added this will be used by `RepoLocationAnalyzer` to figure out if the given URL that you are trying to import from the /catalog-import page already contains catalog-info.yaml files. diff --git a/.changeset/tame-ads-complain.md b/.changeset/tame-ads-complain.md new file mode 100644 index 0000000000..d6b3c47b69 --- /dev/null +++ b/.changeset/tame-ads-complain.md @@ -0,0 +1,18 @@ +--- +'@backstage/plugin-catalog-backend-module-github': patch +--- + +Replaces in-code uses of `GitHub` by `Github` and deprecates old versions. + +Deprecates + +- `GitHubEntityProvider` replaced by `GithubEntityProvider` +- `GitHubLocationAnalyzer` replaced by `GithubLocationAnalyzer` +- `GitHubLocationAnalyzerOptions` replaced by `GithubLocationAnalyzerOptions` +- `GitHubOrgEntityProvider` replaced by `GithubOrgEntityProvider` +- `GitHubOrgEntityProviderOptions` replaced by `GithubOrgEntityProviderOptions` + +Renames + +- `GitHubLocationAnalyzer` to `GithubLocationAnalyzer` +- `GitHubLocationAnalyzerOptions` to `GithubLocationAnalyzerOptions` diff --git a/docs/integrations/github/discovery.md b/docs/integrations/github/discovery.md index 26cd660cde..092a171223 100644 --- a/docs/integrations/github/discovery.md +++ b/docs/integrations/github/discovery.md @@ -30,14 +30,14 @@ And then add the entity provider to your catalog builder: ```diff // In packages/backend/src/plugins/catalog.ts -+ import { GitHubEntityProvider } from '@backstage/plugin-catalog-backend-module-github'; ++ import { GithubEntityProvider } from '@backstage/plugin-catalog-backend-module-github'; export default async function createPlugin( env: PluginEnvironment, ): Promise { const builder = await CatalogBuilder.create(env); + builder.addEntityProvider( -+ GitHubEntityProvider.fromConfig(env.config, { ++ GithubEntityProvider.fromConfig(env.config, { + logger: env.logger, + // optional: alternatively, use scheduler with schedule defined in app-config.yaml + schedule: env.scheduler.createScheduledTaskRunner({ diff --git a/plugins/catalog-backend-module-github/api-report.md b/plugins/catalog-backend-module-github/api-report.md index 4ab534e6d3..5b94f7169e 100644 --- a/plugins/catalog-backend-module-github/api-report.md +++ b/plugins/catalog-backend-module-github/api-report.md @@ -46,7 +46,7 @@ export class GithubDiscoveryProcessor implements CatalogProcessor { ): Promise; } -// @public +// @public @deprecated (undocumented) export class GitHubEntityProvider implements EntityProvider { // (undocumented) connect(connection: EntityProviderConnection): Promise; @@ -65,14 +65,33 @@ export class GitHubEntityProvider implements EntityProvider { refresh(logger: Logger): Promise; } +// @public +export class GithubEntityProvider implements EntityProvider { + // (undocumented) + connect(connection: EntityProviderConnection): Promise; + // (undocumented) + static fromConfig( + config: Config, + options: { + logger: Logger; + schedule?: TaskRunner; + scheduler?: PluginTaskScheduler; + }, + ): GithubEntityProvider[]; + // (undocumented) + getProviderName(): string; + // (undocumented) + refresh(logger: Logger): Promise; +} + // @alpha export const githubEntityProviderCatalogModule: ( options?: undefined, ) => BackendFeature; // @public (undocumented) -export class GitHubLocationAnalyzer implements ScmLocationAnalyzer { - constructor(options: GitHubLocationAnalyzerOptions); +export class GithubLocationAnalyzer implements ScmLocationAnalyzer { + constructor(options: GithubLocationAnalyzerOptions); // (undocumented) analyze({ url, catalogFilename }: AnalyzeOptions): Promise<{ existing: { @@ -89,7 +108,7 @@ export class GitHubLocationAnalyzer implements ScmLocationAnalyzer { } // @public (undocumented) -export type GitHubLocationAnalyzerOptions = { +export type GithubLocationAnalyzerOptions = { config: Config; discovery: PluginEndpointDiscovery; }; @@ -127,8 +146,17 @@ export class GithubMultiOrgReaderProcessor implements CatalogProcessor { ): Promise; } +// @public @deprecated (undocumented) +export class GitHubOrgEntityProvider extends GithubOrgEntityProvider { + // (undocumented) + static fromConfig( + config: Config, + options: GitHubOrgEntityProviderOptions, + ): GitHubOrgEntityProvider; +} + // @public -export class GitHubOrgEntityProvider implements EntityProvider { +export class GithubOrgEntityProvider implements EntityProvider { constructor(options: { id: string; orgUrl: string; @@ -141,15 +169,18 @@ export class GitHubOrgEntityProvider implements EntityProvider { // (undocumented) static fromConfig( config: Config, - options: GitHubOrgEntityProviderOptions, - ): GitHubOrgEntityProvider; + options: GithubOrgEntityProviderOptions, + ): GithubOrgEntityProvider; // (undocumented) getProviderName(): string; read(options?: { logger?: Logger }): Promise; } +// @public @deprecated (undocumented) +export type GitHubOrgEntityProviderOptions = GithubOrgEntityProviderOptions; + // @public -export interface GitHubOrgEntityProviderOptions { +export interface GithubOrgEntityProviderOptions { githubCredentialsProvider?: GithubCredentialsProvider; id: string; logger: Logger; diff --git a/plugins/catalog-backend-module-github/config.d.ts b/plugins/catalog-backend-module-github/config.d.ts index 8648490001..691caedc46 100644 --- a/plugins/catalog-backend-module-github/config.d.ts +++ b/plugins/catalog-backend-module-github/config.d.ts @@ -50,7 +50,7 @@ export interface Config { providers?: { /** - * GitHubEntityProvider configuration + * GithubEntityProvider configuration * * Uses "default" as default id for the single config variant. */ diff --git a/plugins/catalog-backend-module-github/src/analyzers/GitHubLocationAnalyzer.test.ts b/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.test.ts similarity index 95% rename from plugins/catalog-backend-module-github/src/analyzers/GitHubLocationAnalyzer.test.ts rename to plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.test.ts index 0dcc131502..936f8a3576 100644 --- a/plugins/catalog-backend-module-github/src/analyzers/GitHubLocationAnalyzer.test.ts +++ b/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.test.ts @@ -33,7 +33,7 @@ jest.mock('@octokit/rest', () => { }); import { PluginEndpointDiscovery } from '@backstage/backend-common'; -import { GitHubLocationAnalyzer } from './GitHubLocationAnalyzer'; +import { GithubLocationAnalyzer } from './GithubLocationAnalyzer'; import { setupRequestMockHandlers } from '@backstage/backend-test-utils'; import { setupServer } from 'msw/node'; import { rest } from 'msw'; @@ -41,7 +41,7 @@ import { ConfigReader } from '@backstage/config'; const server = setupServer(); -describe('GitHubLocationAnalyzer', () => { +describe('GithubLocationAnalyzer', () => { const mockDiscoveryApi: jest.Mocked = { getBaseUrl: jest.fn().mockResolvedValue('http://localhost:7007'), getExternalBaseUrl: jest.fn(), @@ -114,7 +114,7 @@ describe('GitHubLocationAnalyzer', () => { return Promise.reject(); }); - const analyzer = new GitHubLocationAnalyzer({ + const analyzer = new GithubLocationAnalyzer({ discovery: mockDiscoveryApi, config, }); @@ -139,7 +139,7 @@ describe('GitHubLocationAnalyzer', () => { return Promise.reject(); }); - const analyzer = new GitHubLocationAnalyzer({ + const analyzer = new GithubLocationAnalyzer({ discovery: mockDiscoveryApi, config, }); diff --git a/plugins/catalog-backend-module-github/src/analyzers/GitHubLocationAnalyzer.ts b/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.ts similarity index 95% rename from plugins/catalog-backend-module-github/src/analyzers/GitHubLocationAnalyzer.ts rename to plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.ts index d1112d2cc0..32ef8bf946 100644 --- a/plugins/catalog-backend-module-github/src/analyzers/GitHubLocationAnalyzer.ts +++ b/plugins/catalog-backend-module-github/src/analyzers/GithubLocationAnalyzer.ts @@ -27,24 +27,27 @@ import { PluginEndpointDiscovery } from '@backstage/backend-common'; import { Config } from '@backstage/config'; /** @public */ -export type GitHubLocationAnalyzerOptions = { +export type GithubLocationAnalyzerOptions = { config: Config; discovery: PluginEndpointDiscovery; }; + /** @public */ -export class GitHubLocationAnalyzer implements ScmLocationAnalyzer { +export class GithubLocationAnalyzer implements ScmLocationAnalyzer { private readonly catalogClient: CatalogApi; private readonly config: Config; - constructor(options: GitHubLocationAnalyzerOptions) { + constructor(options: GithubLocationAnalyzerOptions) { this.config = options.config; this.catalogClient = new CatalogClient({ discoveryApi: options.discovery }); } + supports(url: string) { const integrations = ScmIntegrations.fromConfig(this.config); const integration = integrations.byUrl(url); return integration?.type === 'github'; } + async analyze({ url, catalogFilename }: AnalyzeOptions) { const { owner, name: repo } = parseGitUrl(url); diff --git a/plugins/catalog-backend-module-github/src/deprecated.ts b/plugins/catalog-backend-module-github/src/deprecated.ts new file mode 100644 index 0000000000..d094bb4031 --- /dev/null +++ b/plugins/catalog-backend-module-github/src/deprecated.ts @@ -0,0 +1,86 @@ +/* + * Copyright 2020 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 { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks'; +import { Config } from '@backstage/config'; +import { + EntityProvider, + EntityProviderConnection, +} from '@backstage/plugin-catalog-backend'; +import { Logger } from 'winston'; +import { GithubEntityProvider } from './providers/GithubEntityProvider'; +import { + GithubOrgEntityProvider, + GithubOrgEntityProviderOptions, +} from './providers/GithubOrgEntityProvider'; + +/** + * @public + * @deprecated Use {@link GithubOrgEntityProvider} instead. + */ +export class GitHubOrgEntityProvider extends GithubOrgEntityProvider { + static fromConfig(config: Config, options: GitHubOrgEntityProviderOptions) { + options.logger.warn( + '[Deprecated] Use GithubOrgEntityProvider instead of GitHubOrgEntityProvider.', + ); + return GithubOrgEntityProvider.fromConfig( + config, + options as GithubOrgEntityProviderOptions, + ) as GitHubOrgEntityProvider; + } +} + +/** + * @public + * @deprecated Use {@link GithubOrgEntityProviderOptions} instead. + */ +export type GitHubOrgEntityProviderOptions = GithubOrgEntityProviderOptions; + +/** + * @public + * @deprecated Use {@link GithubEntityProvider} instead. + */ +export class GitHubEntityProvider implements EntityProvider { + static fromConfig( + config: Config, + options: { + logger: Logger; + schedule?: TaskRunner; + scheduler?: PluginTaskScheduler; + }, + ): GitHubEntityProvider[] { + options.logger.warn( + '[Deprecated] Please use GithubEntityProvider instead of GitHubEntityProvider.', + ); + return GithubEntityProvider.fromConfig(config, options).map( + delegate => new GitHubEntityProvider(delegate), + ); + } + + private constructor(private readonly delegate: GithubEntityProvider) {} + + connect(connection: EntityProviderConnection): Promise { + return this.delegate.connect(connection); + } + + getProviderName(): string { + return this.delegate.getProviderName(); + } + + refresh(logger: Logger): Promise { + return this.delegate.refresh(logger); + } +} diff --git a/plugins/catalog-backend-module-github/src/index.ts b/plugins/catalog-backend-module-github/src/index.ts index 3d7a7a2b4e..f38035db15 100644 --- a/plugins/catalog-backend-module-github/src/index.ts +++ b/plugins/catalog-backend-module-github/src/index.ts @@ -20,13 +20,15 @@ * @packageDocumentation */ -export { GitHubLocationAnalyzer } from './analyzers/GitHubLocationAnalyzer'; -export type { GitHubLocationAnalyzerOptions } from './analyzers/GitHubLocationAnalyzer'; +export { GithubLocationAnalyzer } from './analyzers/GithubLocationAnalyzer'; +export type { GithubLocationAnalyzerOptions } from './analyzers/GithubLocationAnalyzer'; export type { GithubMultiOrgConfig } from './lib'; export { GithubDiscoveryProcessor } from './processors/GithubDiscoveryProcessor'; export { GithubMultiOrgReaderProcessor } from './processors/GithubMultiOrgReaderProcessor'; export { GithubOrgReaderProcessor } from './processors/GithubOrgReaderProcessor'; -export { GitHubEntityProvider } from './providers/GitHubEntityProvider'; -export { GitHubOrgEntityProvider } from './providers/GitHubOrgEntityProvider'; -export type { GitHubOrgEntityProviderOptions } from './providers/GitHubOrgEntityProvider'; +export { GithubEntityProvider } from './providers/GithubEntityProvider'; +export { GithubOrgEntityProvider } from './providers/GithubOrgEntityProvider'; +export type { GithubOrgEntityProviderOptions } from './providers/GithubOrgEntityProvider'; export { githubEntityProviderCatalogModule } from './service/GithubEntityProviderCatalogModule'; + +export * from './deprecated'; diff --git a/plugins/catalog-backend-module-github/src/lib/index.ts b/plugins/catalog-backend-module-github/src/lib/index.ts index 26ec3e8516..6402b69121 100644 --- a/plugins/catalog-backend-module-github/src/lib/index.ts +++ b/plugins/catalog-backend-module-github/src/lib/index.ts @@ -22,4 +22,4 @@ export { getOrganizationUsers, } from './github'; export { assignGroupsToUsers, buildOrgHierarchy } from './org'; -export { parseGitHubOrgUrl } from './util'; +export { parseGithubOrgUrl } from './util'; diff --git a/plugins/catalog-backend-module-github/src/lib/util.test.ts b/plugins/catalog-backend-module-github/src/lib/util.test.ts index c530d2bcc9..7aca6839ea 100644 --- a/plugins/catalog-backend-module-github/src/lib/util.test.ts +++ b/plugins/catalog-backend-module-github/src/lib/util.test.ts @@ -14,17 +14,17 @@ * limitations under the License. */ -import { GithubTopicFilters } from '../providers/GitHubEntityProviderConfig'; -import { parseGitHubOrgUrl, satisfiesTopicFilter } from './util'; +import { GithubTopicFilters } from '../providers/GithubEntityProviderConfig'; +import { parseGithubOrgUrl, satisfiesTopicFilter } from './util'; -describe('parseGitHubOrgUrl', () => { +describe('parseGithubOrgUrl', () => { it('only supports clean org urls, and decodes them', () => { - expect(() => parseGitHubOrgUrl('https://github.com')).toThrow(); - expect(() => parseGitHubOrgUrl('https://github.com/org/foo')).toThrow(); + expect(() => parseGithubOrgUrl('https://github.com')).toThrow(); + expect(() => parseGithubOrgUrl('https://github.com/org/foo')).toThrow(); expect(() => - parseGitHubOrgUrl('https://github.com/org/foo/teams'), + parseGithubOrgUrl('https://github.com/org/foo/teams'), ).toThrow(); - expect(parseGitHubOrgUrl('https://github.com/foo%32')).toEqual({ + expect(parseGithubOrgUrl('https://github.com/foo%32')).toEqual({ org: 'foo2', }); }); diff --git a/plugins/catalog-backend-module-github/src/lib/util.ts b/plugins/catalog-backend-module-github/src/lib/util.ts index 238ed9868a..ece463bb40 100644 --- a/plugins/catalog-backend-module-github/src/lib/util.ts +++ b/plugins/catalog-backend-module-github/src/lib/util.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { GithubTopicFilters } from '../providers/GitHubEntityProviderConfig'; +import { GithubTopicFilters } from '../providers/GithubEntityProviderConfig'; -export function parseGitHubOrgUrl(urlString: string): { org: string } { +export function parseGithubOrgUrl(urlString: string): { org: string } { const path = new URL(urlString).pathname.substr(1).split('/'); // /backstage diff --git a/plugins/catalog-backend-module-github/src/processors/GithubOrgReaderProcessor.ts b/plugins/catalog-backend-module-github/src/processors/GithubOrgReaderProcessor.ts index c6f2f5d0e2..0ef81ac907 100644 --- a/plugins/catalog-backend-module-github/src/processors/GithubOrgReaderProcessor.ts +++ b/plugins/catalog-backend-module-github/src/processors/GithubOrgReaderProcessor.ts @@ -35,7 +35,7 @@ import { buildOrgHierarchy, getOrganizationTeams, getOrganizationUsers, - parseGitHubOrgUrl, + parseGithubOrgUrl, } from '../lib'; type GraphQL = typeof graphql; @@ -45,7 +45,7 @@ type GraphQL = typeof graphql; * * @remarks * - * Consider using {@link GitHubOrgEntityProvider} instead. + * Consider using {@link GithubOrgEntityProvider} instead. * * @public */ @@ -94,7 +94,7 @@ export class GithubOrgReaderProcessor implements CatalogProcessor { } const { client, tokenType } = await this.createClient(location.target); - const { org } = parseGitHubOrgUrl(location.target); + const { org } = parseGithubOrgUrl(location.target); // Read out all of the raw data const startTimestamp = Date.now(); diff --git a/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.test.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.test.ts similarity index 95% rename from plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.test.ts rename to plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.test.ts index b2078172e9..a63069d552 100644 --- a/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.test.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.test.ts @@ -22,7 +22,7 @@ import { } from '@backstage/backend-tasks'; import { ConfigReader } from '@backstage/config'; import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; -import { GitHubEntityProvider } from './GitHubEntityProvider'; +import { GithubEntityProvider } from './GithubEntityProvider'; import * as helpers from '../lib/github'; jest.mock('../lib/github', () => { @@ -45,13 +45,13 @@ class PersistingTaskRunner implements TaskRunner { const logger = getVoidLogger(); -describe('GitHubEntityProvider', () => { +describe('GithubEntityProvider', () => { afterEach(() => jest.resetAllMocks()); it('no provider config', () => { const schedule = new PersistingTaskRunner(); const config = new ConfigReader({}); - const providers = GitHubEntityProvider.fromConfig(config, { + const providers = GithubEntityProvider.fromConfig(config, { logger, schedule, }); @@ -70,7 +70,7 @@ describe('GitHubEntityProvider', () => { }, }, }); - const providers = GitHubEntityProvider.fromConfig(config, { + const providers = GithubEntityProvider.fromConfig(config, { logger, schedule, }); @@ -93,7 +93,7 @@ describe('GitHubEntityProvider', () => { }); expect(() => - GitHubEntityProvider.fromConfig(config, { + GithubEntityProvider.fromConfig(config, { logger, schedule, }), @@ -116,7 +116,7 @@ describe('GitHubEntityProvider', () => { }, }, }); - const providers = GitHubEntityProvider.fromConfig(config, { + const providers = GithubEntityProvider.fromConfig(config, { logger, schedule, }); @@ -153,7 +153,7 @@ describe('GitHubEntityProvider', () => { refresh: jest.fn(), }; - const provider = GitHubEntityProvider.fromConfig(config, { + const provider = GithubEntityProvider.fromConfig(config, { logger, schedule, })[0]; @@ -241,7 +241,7 @@ describe('GitHubEntityProvider', () => { refresh: jest.fn(), }; - const provider = GitHubEntityProvider.fromConfig(config, { + const provider = GithubEntityProvider.fromConfig(config, { logger, schedule, })[0]; @@ -315,7 +315,7 @@ describe('GitHubEntityProvider', () => { refresh: jest.fn(), }; - const provider = GitHubEntityProvider.fromConfig(config, { + const provider = GithubEntityProvider.fromConfig(config, { logger, schedule, })[0]; @@ -413,7 +413,7 @@ describe('GitHubEntityProvider', () => { refresh: jest.fn(), }; - const provider = GitHubEntityProvider.fromConfig(config, { + const provider = GithubEntityProvider.fromConfig(config, { logger, schedule, })[0]; @@ -526,7 +526,7 @@ describe('GitHubEntityProvider', () => { }); expect(() => - GitHubEntityProvider.fromConfig(config, { + GithubEntityProvider.fromConfig(config, { logger, }), ).toThrow('Either schedule or scheduler must be provided'); @@ -547,7 +547,7 @@ describe('GitHubEntityProvider', () => { }); expect(() => - GitHubEntityProvider.fromConfig(config, { + GithubEntityProvider.fromConfig(config, { logger, scheduler, }), @@ -574,7 +574,7 @@ describe('GitHubEntityProvider', () => { }, }, }); - const providers = GitHubEntityProvider.fromConfig(config, { + const providers = GithubEntityProvider.fromConfig(config, { logger, scheduler, }); diff --git a/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts similarity index 95% rename from plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.ts rename to plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts index 7d04b749dd..2004cb7469 100644 --- a/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts @@ -35,8 +35,8 @@ import * as uuid from 'uuid'; import { Logger } from 'winston'; import { readProviderConfigs, - GitHubEntityProviderConfig, -} from './GitHubEntityProviderConfig'; + GithubEntityProviderConfig, +} from './GithubEntityProviderConfig'; import { getOrganizationRepositories, Repository } from '../lib/github'; import { satisfiesTopicFilter } from '../lib/util'; @@ -48,8 +48,8 @@ import { satisfiesTopicFilter } from '../lib/util'; * * @public */ -export class GitHubEntityProvider implements EntityProvider { - private readonly config: GitHubEntityProviderConfig; +export class GithubEntityProvider implements EntityProvider { + private readonly config: GithubEntityProviderConfig; private readonly logger: Logger; private readonly integration: GitHubIntegrationConfig; private readonly scheduleFn: () => Promise; @@ -63,7 +63,7 @@ export class GitHubEntityProvider implements EntityProvider { schedule?: TaskRunner; scheduler?: PluginTaskScheduler; }, - ): GitHubEntityProvider[] { + ): GithubEntityProvider[] { if (!options.schedule && !options.scheduler) { throw new Error('Either schedule or scheduler must be provided.'); } @@ -90,7 +90,7 @@ export class GitHubEntityProvider implements EntityProvider { options.schedule ?? options.scheduler!.createScheduledTaskRunner(providerConfig.schedule!); - return new GitHubEntityProvider( + return new GithubEntityProvider( providerConfig, integration, options.logger, @@ -100,7 +100,7 @@ export class GitHubEntityProvider implements EntityProvider { } private constructor( - config: GitHubEntityProviderConfig, + config: GithubEntityProviderConfig, integration: GitHubIntegration, logger: Logger, taskRunner: TaskRunner, @@ -133,7 +133,7 @@ export class GitHubEntityProvider implements EntityProvider { id: taskId, fn: async () => { const logger = this.logger.child({ - class: GitHubEntityProvider.prototype.constructor.name, + class: GithubEntityProvider.prototype.constructor.name, taskId, taskInstanceId: uuid.v4(), }); @@ -156,7 +156,7 @@ export class GitHubEntityProvider implements EntityProvider { const matchingTargets = this.matchesFilters(targets); const entities = matchingTargets .map(repository => this.createLocationUrl(repository)) - .map(GitHubEntityProvider.toLocationSpec) + .map(GithubEntityProvider.toLocationSpec) .map(location => { return { locationKey: this.getProviderName(), diff --git a/plugins/catalog-backend-module-github/src/providers/GitHubEntityProviderConfig.test.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts similarity index 98% rename from plugins/catalog-backend-module-github/src/providers/GitHubEntityProviderConfig.test.ts rename to plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts index e1b3a6cfbf..c80546bdff 100644 --- a/plugins/catalog-backend-module-github/src/providers/GitHubEntityProviderConfig.test.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts @@ -16,7 +16,7 @@ import { ConfigReader } from '@backstage/config'; import { Duration } from 'luxon'; -import { readProviderConfigs } from './GitHubEntityProviderConfig'; +import { readProviderConfigs } from './GithubEntityProviderConfig'; describe('readProviderConfigs', () => { afterEach(() => jest.resetAllMocks()); diff --git a/plugins/catalog-backend-module-github/src/providers/GitHubEntityProviderConfig.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts similarity index 96% rename from plugins/catalog-backend-module-github/src/providers/GitHubEntityProviderConfig.ts rename to plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts index 6785d18984..18c0a3915d 100644 --- a/plugins/catalog-backend-module-github/src/providers/GitHubEntityProviderConfig.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts @@ -23,7 +23,7 @@ import { Config } from '@backstage/config'; const DEFAULT_CATALOG_PATH = '/catalog-info.yaml'; const DEFAULT_PROVIDER_ID = 'default'; -export type GitHubEntityProviderConfig = { +export type GithubEntityProviderConfig = { id: string; catalogPath: string; organization: string; @@ -43,7 +43,7 @@ export type GithubTopicFilters = { export function readProviderConfigs( config: Config, -): GitHubEntityProviderConfig[] { +): GithubEntityProviderConfig[] { const providersConfig = config.getOptionalConfig('catalog.providers.github'); if (!providersConfig) { return []; @@ -64,7 +64,7 @@ export function readProviderConfigs( function readProviderConfig( id: string, config: Config, -): GitHubEntityProviderConfig { +): GithubEntityProviderConfig { const organization = config.getString('organization'); const catalogPath = config.getOptionalString('catalogPath') ?? DEFAULT_CATALOG_PATH; diff --git a/plugins/catalog-backend-module-github/src/providers/GitHubOrgEntityProvider.test.ts b/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.test.ts similarity index 97% rename from plugins/catalog-backend-module-github/src/providers/GitHubOrgEntityProvider.test.ts rename to plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.test.ts index 2d05346f01..1d8d125d91 100644 --- a/plugins/catalog-backend-module-github/src/providers/GitHubOrgEntityProvider.test.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.test.ts @@ -23,13 +23,13 @@ import { import { EntityProviderConnection } from '@backstage/plugin-catalog-backend'; import { graphql } from '@octokit/graphql'; import { - GitHubOrgEntityProvider, + GithubOrgEntityProvider, withLocations, -} from './GitHubOrgEntityProvider'; +} from './GithubOrgEntityProvider'; jest.mock('@octokit/graphql'); -describe('GitHubOrgEntityProvider', () => { +describe('GithubOrgEntityProvider', () => { describe('read', () => { afterEach(() => jest.resetAllMocks()); @@ -100,7 +100,7 @@ describe('GitHubOrgEntityProvider', () => { getCredentials: mockGetCredentials, }; - const entityProvider = new GitHubOrgEntityProvider({ + const entityProvider = new GithubOrgEntityProvider({ id: 'my-id', githubCredentialsProvider, orgUrl: 'https://github.com/backstage', diff --git a/plugins/catalog-backend-module-github/src/providers/GitHubOrgEntityProvider.ts b/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts similarity index 92% rename from plugins/catalog-backend-module-github/src/providers/GitHubOrgEntityProvider.ts rename to plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts index bb994c193c..f8fafbe53c 100644 --- a/plugins/catalog-backend-module-github/src/providers/GitHubOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts @@ -41,15 +41,15 @@ import { buildOrgHierarchy, getOrganizationTeams, getOrganizationUsers, - parseGitHubOrgUrl, + parseGithubOrgUrl, } from '../lib'; /** - * Options for {@link GitHubOrgEntityProvider}. + * Options for {@link GithubOrgEntityProvider}. * * @public */ -export interface GitHubOrgEntityProviderOptions { +export interface GithubOrgEntityProviderOptions { /** * A unique, stable identifier for this provider. * @@ -96,12 +96,12 @@ export interface GitHubOrgEntityProviderOptions { * * @public */ -export class GitHubOrgEntityProvider implements EntityProvider { +export class GithubOrgEntityProvider implements EntityProvider { private readonly credentialsProvider: GithubCredentialsProvider; private connection?: EntityProviderConnection; private scheduleFn?: () => Promise; - static fromConfig(config: Config, options: GitHubOrgEntityProviderOptions) { + static fromConfig(config: Config, options: GithubOrgEntityProviderOptions) { const integrations = ScmIntegrations.fromConfig(config); const gitHubConfig = integrations.github.byUrl(options.orgUrl)?.config; @@ -115,7 +115,7 @@ export class GitHubOrgEntityProvider implements EntityProvider { target: options.orgUrl, }); - const provider = new GitHubOrgEntityProvider({ + const provider = new GithubOrgEntityProvider({ id: options.id, orgUrl: options.orgUrl, logger, @@ -146,7 +146,7 @@ export class GitHubOrgEntityProvider implements EntityProvider { /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */ getProviderName() { - return `GitHubOrgEntityProvider:${this.options.id}`; + return `GithubOrgEntityProvider:${this.options.id}`; } /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */ @@ -176,7 +176,7 @@ export class GitHubOrgEntityProvider implements EntityProvider { headers, }); - const { org } = parseGitHubOrgUrl(this.options.orgUrl); + const { org } = parseGithubOrgUrl(this.options.orgUrl); const { users } = await getOrganizationUsers(client, org, tokenType); const { groups, groupMemberUsers } = await getOrganizationTeams( client, @@ -202,7 +202,7 @@ export class GitHubOrgEntityProvider implements EntityProvider { markCommitComplete(); } - private schedule(schedule: GitHubOrgEntityProviderOptions['schedule']) { + private schedule(schedule: GithubOrgEntityProviderOptions['schedule']) { if (!schedule || schedule === 'manual') { return; } @@ -213,7 +213,7 @@ export class GitHubOrgEntityProvider implements EntityProvider { id, fn: async () => { const logger = this.options.logger.child({ - class: GitHubOrgEntityProvider.prototype.constructor.name, + class: GithubOrgEntityProvider.prototype.constructor.name, taskId: id, taskInstanceId: uuid.v4(), }); diff --git a/plugins/catalog-backend-module-github/src/service/GithubEntityProviderCatalogModule.test.ts b/plugins/catalog-backend-module-github/src/service/GithubEntityProviderCatalogModule.test.ts index d65eb98661..b555927d2c 100644 --- a/plugins/catalog-backend-module-github/src/service/GithubEntityProviderCatalogModule.test.ts +++ b/plugins/catalog-backend-module-github/src/service/GithubEntityProviderCatalogModule.test.ts @@ -29,11 +29,11 @@ import { ConfigReader } from '@backstage/config'; import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node'; import { Duration } from 'luxon'; import { githubEntityProviderCatalogModule } from './GithubEntityProviderCatalogModule'; -import { GitHubEntityProvider } from '../providers/GitHubEntityProvider'; +import { GithubEntityProvider } from '../providers/GithubEntityProvider'; describe('githubEntityProviderCatalogModule', () => { it('should register provider at the catalog extension point', async () => { - let addedProviders: Array | undefined; + let addedProviders: Array | undefined; let usedSchedule: TaskScheduleDefinition | undefined; const extensionPoint = { diff --git a/plugins/catalog-backend-module-github/src/service/GithubEntityProviderCatalogModule.ts b/plugins/catalog-backend-module-github/src/service/GithubEntityProviderCatalogModule.ts index c63e8ba7da..8fdee886a3 100644 --- a/plugins/catalog-backend-module-github/src/service/GithubEntityProviderCatalogModule.ts +++ b/plugins/catalog-backend-module-github/src/service/GithubEntityProviderCatalogModule.ts @@ -22,10 +22,10 @@ import { schedulerServiceRef, } from '@backstage/backend-plugin-api'; import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node'; -import { GitHubEntityProvider } from '../providers/GitHubEntityProvider'; +import { GithubEntityProvider } from '../providers/GithubEntityProvider'; /** - * Registers the GitHubEntityProvider with the catalog processing extension point. + * Registers the {@link GithubEntityProvider} with the catalog processing extension point. * * @alpha */ @@ -42,7 +42,7 @@ export const githubEntityProviderCatalogModule = createBackendModule({ }, async init({ catalog, config, logger, scheduler }) { catalog.addEntityProvider( - GitHubEntityProvider.fromConfig(config, { + GithubEntityProvider.fromConfig(config, { logger: loggerToWinstonLogger(logger), scheduler, }),