Merge pull request #9870 from backstage/jhaals/dep-BitbucketRepositoryParser
catalog-backend: inline and deprecate BitbucketRepositoryParser type
This commit is contained in:
@@ -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;
|
||||
|
||||
+10
-11
@@ -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;
|
||||
|
||||
-4
@@ -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
-12
@@ -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',
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user