catalog-backend: inline and deprecate BitbucketRepositoryParser type

Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com>
Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2022-03-01 11:13:28 +01:00
parent f587dcc5bf
commit be68702834
5 changed files with 63 additions and 35 deletions
+11 -3
View File
@@ -137,14 +137,22 @@ export class AzureDevOpsDiscoveryProcessor implements CatalogProcessor {
export class BitbucketDiscoveryProcessor implements CatalogProcessor {
constructor(options: {
integrations: ScmIntegrationRegistry;
parser?: BitbucketRepositoryParser;
parser?: (options: {
integration: BitbucketIntegration;
target: string;
logger: Logger_2;
}) => AsyncIterable<CatalogProcessorResult>;
logger: Logger_2;
});
// (undocumented)
static fromConfig(
config: Config,
options: {
parser?: BitbucketRepositoryParser;
parser?: (options: {
integration: BitbucketIntegration;
target: string;
logger: Logger_2;
}) => AsyncIterable<CatalogProcessorResult>;
logger: Logger_2;
},
): BitbucketDiscoveryProcessor;
@@ -158,7 +166,7 @@ export class BitbucketDiscoveryProcessor implements CatalogProcessor {
): Promise<boolean>;
}
// @public (undocumented)
// @public @deprecated (undocumented)
export type BitbucketRepositoryParser = (options: {
integration: BitbucketIntegration;
target: string;
@@ -18,7 +18,6 @@ import { BitbucketDiscoveryProcessor } from './BitbucketDiscoveryProcessor';
import { ConfigReader } from '@backstage/config';
import {
BitbucketRepository20,
BitbucketRepositoryParser,
PagedResponse,
PagedResponse20,
} from './bitbucket';
@@ -742,15 +741,6 @@ describe('BitbucketDiscoveryProcessor', () => {
});
describe('Custom repository parser', () => {
const customRepositoryParser: BitbucketRepositoryParser =
async function* customRepositoryParser({}) {
yield results.location({
type: 'custom-location-type',
target: 'custom-target',
presence: 'optional',
});
};
const processor = BitbucketDiscoveryProcessor.fromConfig(
new ConfigReader({
integrations: {
@@ -763,7 +753,16 @@ describe('BitbucketDiscoveryProcessor', () => {
],
},
}),
{ parser: customRepositoryParser, logger: getVoidLogger() },
{
parser: async function* customRepositoryParser({}) {
yield results.location({
type: 'custom-location-type',
target: 'custom-target',
presence: 'optional',
});
},
logger: getVoidLogger(),
},
);
it('use custom repository parser', async () => {
@@ -22,7 +22,6 @@ import {
ScmIntegrations,
} from '@backstage/integration';
import {
BitbucketRepositoryParser,
BitbucketClient,
defaultRepositoryParser,
paginated,
@@ -30,7 +29,12 @@ import {
BitbucketRepository,
BitbucketRepository20,
} from './bitbucket';
import { CatalogProcessor, CatalogProcessorEmit, LocationSpec } from './types';
import {
CatalogProcessor,
CatalogProcessorEmit,
CatalogProcessorResult,
LocationSpec,
} from './types';
const DEFAULT_BRANCH = 'master';
const DEFAULT_CATALOG_LOCATION = '/catalog-info.yaml';
@@ -39,12 +43,23 @@ const EMPTY_CATALOG_LOCATION = '/';
/** @public */
export class BitbucketDiscoveryProcessor implements CatalogProcessor {
private readonly integrations: ScmIntegrationRegistry;
private readonly parser: BitbucketRepositoryParser;
private readonly parser: (options: {
integration: BitbucketIntegration;
target: string;
logger: Logger;
}) => AsyncIterable<CatalogProcessorResult>;
private readonly logger: Logger;
static fromConfig(
config: Config,
options: { parser?: BitbucketRepositoryParser; logger: Logger },
options: {
parser?: (options: {
integration: BitbucketIntegration;
target: string;
logger: Logger;
}) => AsyncIterable<CatalogProcessorResult>;
logger: Logger;
},
) {
const integrations = ScmIntegrations.fromConfig(config);
@@ -56,7 +71,11 @@ export class BitbucketDiscoveryProcessor implements CatalogProcessor {
constructor(options: {
integrations: ScmIntegrationRegistry;
parser?: BitbucketRepositoryParser;
parser?: (options: {
integration: BitbucketIntegration;
target: string;
logger: Logger;
}) => AsyncIterable<CatalogProcessorResult>;
logger: Logger;
}) {
this.integrations = options.integrations;
@@ -15,8 +15,6 @@
*/
import { defaultRepositoryParser } from './BitbucketRepositoryParser';
import { results } from '../index';
import { getVoidLogger } from '@backstage/backend-common';
import { BitbucketIntegration } from '@backstage/integration';
describe('BitbucketRepositoryParser', () => {
describe('defaultRepositoryParser', () => {
@@ -32,9 +30,7 @@ describe('BitbucketRepositoryParser', () => {
}),
];
const actual = await defaultRepositoryParser({
integration: {} as BitbucketIntegration,
target: `${browseUrl}${path}`,
logger: getVoidLogger(),
});
let i = 0;
@@ -18,21 +18,27 @@ import { results } from '../index';
import { Logger } from 'winston';
import { BitbucketIntegration } from '@backstage/integration';
/** @public */
/**
* @public
* @deprecated type inlined.
*/
export type BitbucketRepositoryParser = (options: {
integration: BitbucketIntegration;
target: string;
logger: Logger;
}) => AsyncIterable<CatalogProcessorResult>;
export const defaultRepositoryParser: BitbucketRepositoryParser =
async function* defaultRepositoryParser({ target }) {
yield results.location({
type: 'url',
target: target,
// Not all locations may actually exist, since the user defined them as a wildcard pattern.
// Thus, we emit them as optional and let the downstream processor find them while not outputting
// an error if it couldn't.
presence: 'optional',
});
};
export const defaultRepositoryParser = async function* defaultRepositoryParser({
target,
}: {
target: string;
}) {
yield results.location({
type: 'url',
target: target,
// Not all locations may actually exist, since the user defined them as a wildcard pattern.
// Thus, we emit them as optional and let the downstream processor find them while not outputting
// an error if it couldn't.
presence: 'optional',
});
};