diff --git a/.changeset/clever-garlics-rescue.md b/.changeset/clever-garlics-rescue.md index a7dd387042..b8ce8f74e8 100644 --- a/.changeset/clever-garlics-rescue.md +++ b/.changeset/clever-garlics-rescue.md @@ -17,4 +17,21 @@ + ); ``` +**BREAKING**: Removed `BitbucketDiscoveryProcessor`, which now instead should be imported from `@backstage/plugin-catalog-backend-module-bitbucket`. NOTE THAT this processor was part of the default set of processors in the catalog backend, and if you are a user of discovery on Bitbucket, you MUST now add it manually in the catalog initialization code of your backend. + +```diff +// In packages/backend/src/plugins/catalog.ts ++import { BitbucketDiscoveryProcessor } from '@backstage/plugin-catalog-backend-module-bitbucket'; + + export default async function createPlugin( + env: PluginEnvironment, + ): Promise { + const builder = await CatalogBuilder.create(env); ++ builder.addProcessor( ++ BitbucketDiscoveryProcessor.fromConfig(env.config, { logger: env.logger }) ++ ); +``` + **BREAKING**: Removed `AzureDevOpsDiscoveryProcessor`, which now instead should be imported from `@backstage/plugin-catalog-backend-module-azure`. This processor was not part of the set of default processors. If you were using it, you should already have a reference to it in your backend code and only need to update the import. + +**BREAKING**: Removed the formerly deprecated type `BitbucketRepositoryParser`, which is no longer necessary since its only use was in `BitbucketDiscoveryProcessor` but is now instead inlined there. diff --git a/.changeset/silent-mugs-roll.md b/.changeset/silent-mugs-roll.md new file mode 100644 index 0000000000..5081022b05 --- /dev/null +++ b/.changeset/silent-mugs-roll.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-bitbucket': minor +--- + +Added package, moving out Bitbucket specific functionality from the catalog-backend diff --git a/.github/styles/vocab.txt b/.github/styles/vocab.txt index 2614dd6b50..aa9d1982c5 100644 --- a/.github/styles/vocab.txt +++ b/.github/styles/vocab.txt @@ -24,7 +24,7 @@ backported backporting Bigtable Billett -Bitbucket +bitbucket Bitrise Blackbox bool diff --git a/docs/integrations/bitbucket/discovery.md b/docs/integrations/bitbucket/discovery.md index 28b0128f56..c31b3a2eed 100644 --- a/docs/integrations/bitbucket/discovery.md +++ b/docs/integrations/bitbucket/discovery.md @@ -11,6 +11,34 @@ catalog entities located in Bitbucket. The processor will crawl your Bitbucket account and register entities matching the configured path. This can be useful as an alternative to static locations or manually adding things to the catalog. +## Installation + +You will have to add the processor in the catalog initialization code of your +backend. The provider is not installed by default, therefore you have to add a +dependency to `@backstage/plugin-catalog-backend-module-bitbucket` to your backend +package. + +```bash +# From your Backstage root directory +cd packages/backend +yarn add @backstage/plugin-catalog-backend-module-bitbucket +``` + +And then add the processor to your catalog builder: + +```diff +// In packages/backend/src/plugins/catalog.ts ++import { BitbucketDiscoveryProcessor } from '@backstage/plugin-catalog-backend-module-bitbucket'; + + export default async function createPlugin( + env: PluginEnvironment, + ): Promise { + const builder = await CatalogBuilder.create(env); ++ builder.addProcessor( ++ BitbucketDiscoveryProcessor.fromConfig(env.config, { logger: env.logger }) ++ ); +``` + ## Self-hosted Bitbucket Server To use the discovery processor with a self-hosted Bitbucket Server, you'll need @@ -137,14 +165,11 @@ matching repository is processed. repository. ```typescript -const customRepositoryParser: BitbucketRepositoryParser = - async function* customRepositoryParser({ client, repository }) { - // Custom logic for interpret the matching repository. - // See defaultRepositoryParser for an example - }; - const processor = BitbucketDiscoveryProcessor.fromConfig(env.config, { - parser: customRepositoryParser, + parser: async function* customRepositoryParser({ client, repository }) { + // Custom logic for interpreting the matching repository. + // See defaultRepositoryParser for an example + }, logger: env.logger, }); ``` diff --git a/plugins/catalog-backend-module-azure/.eslintrc.js b/plugins/catalog-backend-module-azure/.eslintrc.js index 16a033dbc6..e2a53a6ad2 100644 --- a/plugins/catalog-backend-module-azure/.eslintrc.js +++ b/plugins/catalog-backend-module-azure/.eslintrc.js @@ -1,3 +1 @@ -module.exports = { - extends: [require.resolve('@backstage/cli/config/eslint.backend')], -}; +module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); diff --git a/plugins/catalog-backend-module-bitbucket/.eslintrc.js b/plugins/catalog-backend-module-bitbucket/.eslintrc.js new file mode 100644 index 0000000000..e2a53a6ad2 --- /dev/null +++ b/plugins/catalog-backend-module-bitbucket/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); diff --git a/plugins/catalog-backend-module-bitbucket/README.md b/plugins/catalog-backend-module-bitbucket/README.md new file mode 100644 index 0000000000..ae22c7a427 --- /dev/null +++ b/plugins/catalog-backend-module-bitbucket/README.md @@ -0,0 +1,8 @@ +# Catalog Backend Module for Bitbucket + +This is an extension module to the plugin-catalog-backend plugin, providing extensions targeted at Bitbucket offerings. + +## Getting started + +See [Backstage documentation](https://backstage.io/docs/integrations/bitbucket/discovery) for details on how to install +and configure the plugin. diff --git a/plugins/catalog-backend-module-bitbucket/api-report.md b/plugins/catalog-backend-module-bitbucket/api-report.md new file mode 100644 index 0000000000..e8d7791a74 --- /dev/null +++ b/plugins/catalog-backend-module-bitbucket/api-report.md @@ -0,0 +1,49 @@ +## API Report File for "@backstage/plugin-catalog-backend-module-bitbucket" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +import { BitbucketIntegration } from '@backstage/integration'; +import { CatalogProcessor } from '@backstage/plugin-catalog-backend'; +import { CatalogProcessorEmit } from '@backstage/plugin-catalog-backend'; +import { CatalogProcessorResult } from '@backstage/plugin-catalog-backend'; +import { Config } from '@backstage/config'; +import { LocationSpec } from '@backstage/plugin-catalog-backend'; +import { Logger } from 'winston'; +import { ScmIntegrationRegistry } from '@backstage/integration'; + +// @public (undocumented) +export class BitbucketDiscoveryProcessor implements CatalogProcessor { + constructor(options: { + integrations: ScmIntegrationRegistry; + parser?: (options: { + integration: BitbucketIntegration; + target: string; + presence?: 'optional' | 'required'; + logger: Logger; + }) => AsyncIterable; + logger: Logger; + }); + // (undocumented) + static fromConfig( + config: Config, + options: { + parser?: (options: { + integration: BitbucketIntegration; + target: string; + presence?: 'optional' | 'required'; + logger: Logger; + }) => AsyncIterable; + logger: Logger; + }, + ): BitbucketDiscoveryProcessor; + // (undocumented) + getProcessorName(): string; + // (undocumented) + readLocation( + location: LocationSpec, + _optional: boolean, + emit: CatalogProcessorEmit, + ): Promise; +} +``` diff --git a/plugins/catalog-backend-module-bitbucket/package.json b/plugins/catalog-backend-module-bitbucket/package.json new file mode 100644 index 0000000000..8a016196af --- /dev/null +++ b/plugins/catalog-backend-module-bitbucket/package.json @@ -0,0 +1,56 @@ +{ + "name": "@backstage/plugin-catalog-backend-module-bitbucket", + "description": "A Backstage catalog backend module that helps integrate towards Bitbucket", + "version": "0.0.0", + "main": "src/index.ts", + "types": "src/index.ts", + "license": "Apache-2.0", + "private": false, + "publishConfig": { + "access": "public", + "main": "dist/index.cjs.js", + "types": "dist/index.d.ts" + }, + "backstage": { + "role": "backend-plugin-module" + }, + "homepage": "https://backstage.io", + "repository": { + "type": "git", + "url": "https://github.com/backstage/backstage", + "directory": "plugins/catalog-backend-module-bitbucket" + }, + "keywords": [ + "backstage" + ], + "scripts": { + "build": "backstage-cli package build", + "lint": "backstage-cli package lint", + "test": "backstage-cli package test", + "prepack": "backstage-cli package prepack", + "postpack": "backstage-cli package postpack", + "clean": "backstage-cli package clean", + "start": "backstage-cli package start" + }, + "dependencies": { + "@backstage/backend-common": "^0.12.0", + "@backstage/catalog-model": "^0.12.0", + "@backstage/config": "^0.1.15", + "@backstage/errors": "^0.2.2", + "@backstage/integration": "^0.8.0", + "@backstage/plugin-catalog-backend": "^0.23.0", + "@backstage/types": "^0.1.3", + "lodash": "^4.17.21", + "msw": "^0.35.0", + "node-fetch": "^2.6.7", + "winston": "^3.2.1" + }, + "devDependencies": { + "@backstage/backend-test-utils": "^0.1.20", + "@backstage/cli": "^0.15.0", + "@types/lodash": "^4.14.151" + }, + "files": [ + "dist" + ] +} diff --git a/plugins/catalog-backend/src/modules/bitbucket/BitbucketDiscoveryProcessor.test.ts b/plugins/catalog-backend-module-bitbucket/src/BitbucketDiscoveryProcessor.test.ts similarity index 99% rename from plugins/catalog-backend/src/modules/bitbucket/BitbucketDiscoveryProcessor.test.ts rename to plugins/catalog-backend-module-bitbucket/src/BitbucketDiscoveryProcessor.test.ts index a25a5da89e..5f441b787c 100644 --- a/plugins/catalog-backend/src/modules/bitbucket/BitbucketDiscoveryProcessor.test.ts +++ b/plugins/catalog-backend-module-bitbucket/src/BitbucketDiscoveryProcessor.test.ts @@ -15,12 +15,15 @@ */ import { getVoidLogger } from '@backstage/backend-common'; -import { BitbucketDiscoveryProcessor } from './BitbucketDiscoveryProcessor'; import { ConfigReader } from '@backstage/config'; +import { + LocationSpec, + processingResult, +} from '@backstage/plugin-catalog-backend'; import { RequestHandler, rest } from 'msw'; import { setupServer } from 'msw/node'; +import { BitbucketDiscoveryProcessor } from './BitbucketDiscoveryProcessor'; import { BitbucketRepository20, PagedResponse, PagedResponse20 } from './lib'; -import { LocationSpec, processingResult } from '../../api'; const server = setupServer(); diff --git a/plugins/catalog-backend/src/modules/bitbucket/BitbucketDiscoveryProcessor.ts b/plugins/catalog-backend-module-bitbucket/src/BitbucketDiscoveryProcessor.ts similarity index 99% rename from plugins/catalog-backend/src/modules/bitbucket/BitbucketDiscoveryProcessor.ts rename to plugins/catalog-backend-module-bitbucket/src/BitbucketDiscoveryProcessor.ts index 49fa05a762..7c347073ca 100644 --- a/plugins/catalog-backend/src/modules/bitbucket/BitbucketDiscoveryProcessor.ts +++ b/plugins/catalog-backend-module-bitbucket/src/BitbucketDiscoveryProcessor.ts @@ -14,28 +14,27 @@ * limitations under the License. */ -import { Logger } from 'winston'; import { Config } from '@backstage/config'; - import { BitbucketIntegration, ScmIntegrationRegistry, ScmIntegrations, } from '@backstage/integration'; -import { - BitbucketClient, - defaultRepositoryParser, - paginated, - paginated20, - BitbucketRepository, - BitbucketRepository20, -} from './lib'; import { CatalogProcessor, CatalogProcessorEmit, CatalogProcessorResult, LocationSpec, -} from '../../api'; +} from '@backstage/plugin-catalog-backend'; +import { Logger } from 'winston'; +import { + BitbucketClient, + BitbucketRepository, + BitbucketRepository20, + defaultRepositoryParser, + paginated, + paginated20, +} from './lib'; const DEFAULT_BRANCH = 'master'; const DEFAULT_CATALOG_LOCATION = '/catalog-info.yaml'; diff --git a/plugins/catalog-backend/src/modules/bitbucket/index.ts b/plugins/catalog-backend-module-bitbucket/src/index.ts similarity index 80% rename from plugins/catalog-backend/src/modules/bitbucket/index.ts rename to plugins/catalog-backend-module-bitbucket/src/index.ts index 0e39083520..3375fc5a9a 100644 --- a/plugins/catalog-backend/src/modules/bitbucket/index.ts +++ b/plugins/catalog-backend-module-bitbucket/src/index.ts @@ -1,5 +1,5 @@ /* - * Copyright 2022 The Backstage Authors + * 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. @@ -14,5 +14,10 @@ * limitations under the License. */ +/** + * A Backstage catalog backend module that helps integrate towards GitLab + * + * @packageDocumentation + */ + export { BitbucketDiscoveryProcessor } from './BitbucketDiscoveryProcessor'; -export type { BitbucketRepositoryParser } from './lib'; diff --git a/plugins/catalog-backend/src/modules/bitbucket/lib/BitbucketRepositoryParser.test.ts b/plugins/catalog-backend-module-bitbucket/src/lib/BitbucketRepositoryParser.test.ts similarity index 95% rename from plugins/catalog-backend/src/modules/bitbucket/lib/BitbucketRepositoryParser.test.ts rename to plugins/catalog-backend-module-bitbucket/src/lib/BitbucketRepositoryParser.test.ts index 9f2d8b2daa..58845fc3d1 100644 --- a/plugins/catalog-backend/src/modules/bitbucket/lib/BitbucketRepositoryParser.test.ts +++ b/plugins/catalog-backend-module-bitbucket/src/lib/BitbucketRepositoryParser.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { processingResult } from '../../../api'; +import { processingResult } from '@backstage/plugin-catalog-backend'; import { defaultRepositoryParser } from './BitbucketRepositoryParser'; describe('BitbucketRepositoryParser', () => { diff --git a/plugins/catalog-backend/src/modules/bitbucket/lib/BitbucketRepositoryParser.ts b/plugins/catalog-backend-module-bitbucket/src/lib/BitbucketRepositoryParser.ts similarity index 92% rename from plugins/catalog-backend/src/modules/bitbucket/lib/BitbucketRepositoryParser.ts rename to plugins/catalog-backend-module-bitbucket/src/lib/BitbucketRepositoryParser.ts index 8fdcb8f73a..974f2498df 100644 --- a/plugins/catalog-backend/src/modules/bitbucket/lib/BitbucketRepositoryParser.ts +++ b/plugins/catalog-backend-module-bitbucket/src/lib/BitbucketRepositoryParser.ts @@ -15,13 +15,12 @@ */ import { BitbucketIntegration } from '@backstage/integration'; +import { + CatalogProcessorResult, + processingResult, +} from '@backstage/plugin-catalog-backend'; import { Logger } from 'winston'; -import { CatalogProcessorResult, processingResult } from '../../../api'; -/** - * @public - * @deprecated type inlined. - */ export type BitbucketRepositoryParser = (options: { integration: BitbucketIntegration; target: string; diff --git a/plugins/catalog-backend/src/modules/bitbucket/lib/client.ts b/plugins/catalog-backend-module-bitbucket/src/lib/client.ts similarity index 100% rename from plugins/catalog-backend/src/modules/bitbucket/lib/client.ts rename to plugins/catalog-backend-module-bitbucket/src/lib/client.ts index 0ef6558719..a3ee4ab8a6 100644 --- a/plugins/catalog-backend/src/modules/bitbucket/lib/client.ts +++ b/plugins/catalog-backend-module-bitbucket/src/lib/client.ts @@ -14,11 +14,11 @@ * limitations under the License. */ -import fetch from 'node-fetch'; import { BitbucketIntegrationConfig, getBitbucketRequestOptions, } from '@backstage/integration'; +import fetch from 'node-fetch'; import { BitbucketRepository20 } from './types'; export class BitbucketClient { diff --git a/plugins/catalog-backend/src/modules/bitbucket/lib/index.ts b/plugins/catalog-backend-module-bitbucket/src/lib/index.ts similarity index 100% rename from plugins/catalog-backend/src/modules/bitbucket/lib/index.ts rename to plugins/catalog-backend-module-bitbucket/src/lib/index.ts index a819bb3c64..309ec0bce5 100644 --- a/plugins/catalog-backend/src/modules/bitbucket/lib/index.ts +++ b/plugins/catalog-backend-module-bitbucket/src/lib/index.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -export { BitbucketClient, paginated, paginated20 } from './client'; export { defaultRepositoryParser } from './BitbucketRepositoryParser'; +export type { BitbucketRepositoryParser } from './BitbucketRepositoryParser'; +export { BitbucketClient, paginated, paginated20 } from './client'; export type { PagedResponse, PagedResponse20 } from './client'; export type { BitbucketRepository, BitbucketRepository20 } from './types'; -export type { BitbucketRepositoryParser } from './BitbucketRepositoryParser'; diff --git a/plugins/catalog-backend/src/modules/bitbucket/lib/types.ts b/plugins/catalog-backend-module-bitbucket/src/lib/types.ts similarity index 100% rename from plugins/catalog-backend/src/modules/bitbucket/lib/types.ts rename to plugins/catalog-backend-module-bitbucket/src/lib/types.ts diff --git a/plugins/catalog-backend-module-bitbucket/src/setupTests.ts b/plugins/catalog-backend-module-bitbucket/src/setupTests.ts new file mode 100644 index 0000000000..d3232290a7 --- /dev/null +++ b/plugins/catalog-backend-module-bitbucket/src/setupTests.ts @@ -0,0 +1,17 @@ +/* + * 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. + */ + +export {}; diff --git a/plugins/catalog-backend-module-gitlab/.eslintrc.js b/plugins/catalog-backend-module-gitlab/.eslintrc.js index 16a033dbc6..e2a53a6ad2 100644 --- a/plugins/catalog-backend-module-gitlab/.eslintrc.js +++ b/plugins/catalog-backend-module-gitlab/.eslintrc.js @@ -1,3 +1 @@ -module.exports = { - extends: [require.resolve('@backstage/cli/config/eslint.backend')], -}; +module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 2a007fc52c..5669596eb4 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -5,7 +5,6 @@ ```ts /// -import { BitbucketIntegration } from '@backstage/integration'; import { CatalogApi } from '@backstage/catalog-client'; import { CatalogEntityDocument as CatalogEntityDocument_2 } from '@backstage/plugin-catalog-common'; import { CompoundEntityRef } from '@backstage/catalog-model'; @@ -97,49 +96,6 @@ export class AnnotateScmSlugEntityProcessor implements CatalogProcessor { preProcessEntity(entity: Entity, location: LocationSpec): Promise; } -// @public (undocumented) -export class BitbucketDiscoveryProcessor implements CatalogProcessor { - constructor(options: { - integrations: ScmIntegrationRegistry; - parser?: (options: { - integration: BitbucketIntegration; - target: string; - presence?: 'optional' | 'required'; - logger: Logger; - }) => AsyncIterable; - logger: Logger; - }); - // (undocumented) - static fromConfig( - config: Config, - options: { - parser?: (options: { - integration: BitbucketIntegration; - target: string; - presence?: 'optional' | 'required'; - logger: Logger; - }) => AsyncIterable; - logger: Logger; - }, - ): BitbucketDiscoveryProcessor; - // (undocumented) - getProcessorName(): string; - // (undocumented) - readLocation( - location: LocationSpec, - _optional: boolean, - emit: CatalogProcessorEmit, - ): Promise; -} - -// @public @deprecated (undocumented) -export type BitbucketRepositoryParser = (options: { - integration: BitbucketIntegration; - target: string; - presence?: 'optional' | 'required'; - logger: Logger; -}) => AsyncIterable; - // @public (undocumented) export class BuiltinKindsEntityProcessor implements CatalogProcessor { // (undocumented) diff --git a/plugins/catalog-backend/src/modules/index.ts b/plugins/catalog-backend/src/modules/index.ts index c541250c46..6509dcccee 100644 --- a/plugins/catalog-backend/src/modules/index.ts +++ b/plugins/catalog-backend/src/modules/index.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -export * from './bitbucket'; export * from './codeowners'; export * from './core'; export * from './github'; diff --git a/plugins/catalog-backend/src/service/CatalogBuilder.ts b/plugins/catalog-backend/src/service/CatalogBuilder.ts index 768118404e..578f390f09 100644 --- a/plugins/catalog-backend/src/service/CatalogBuilder.ts +++ b/plugins/catalog-backend/src/service/CatalogBuilder.ts @@ -45,7 +45,6 @@ import { } from '../api'; import { AnnotateLocationEntityProcessor, - BitbucketDiscoveryProcessor, BuiltinKindsEntityProcessor, CodeOwnersProcessor, FileReaderProcessor, @@ -357,7 +356,6 @@ export class CatalogBuilder { return [ new FileReaderProcessor(), - BitbucketDiscoveryProcessor.fromConfig(config, { logger }), GithubDiscoveryProcessor.fromConfig(config, { logger, githubCredentialsProvider,