Merge pull request #18918 from kuangp/feat/scmProcessor/kinds
feat(AnnotateScmSlughEntityProcessor): support configuring applicable kinds
This commit is contained in:
@@ -91,9 +91,17 @@ export class AnnotateLocationEntityProcessor implements CatalogProcessor_2 {
|
||||
|
||||
// @public (undocumented)
|
||||
export class AnnotateScmSlugEntityProcessor implements CatalogProcessor_2 {
|
||||
constructor(opts: { scmIntegrationRegistry: ScmIntegrationRegistry });
|
||||
constructor(opts: {
|
||||
scmIntegrationRegistry: ScmIntegrationRegistry;
|
||||
kinds?: string[];
|
||||
});
|
||||
// (undocumented)
|
||||
static fromConfig(config: Config): AnnotateScmSlugEntityProcessor;
|
||||
static fromConfig(
|
||||
config: Config,
|
||||
options?: {
|
||||
kinds?: string[];
|
||||
},
|
||||
): AnnotateScmSlugEntityProcessor;
|
||||
// (undocumented)
|
||||
getProcessorName(): string;
|
||||
// (undocumented)
|
||||
|
||||
@@ -109,6 +109,73 @@ describe('AnnotateScmSlugEntityProcessor', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should only process applicable kinds', async () => {
|
||||
const component: Entity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
};
|
||||
|
||||
const api: Entity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'API',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
};
|
||||
|
||||
const system: Entity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'System',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
};
|
||||
|
||||
const location: LocationSpec = {
|
||||
type: 'url',
|
||||
target:
|
||||
'https://github.com/backstage/backstage/blob/master/catalog-info.yaml',
|
||||
};
|
||||
|
||||
const processor = AnnotateScmSlugEntityProcessor.fromConfig(
|
||||
new ConfigReader({}),
|
||||
{ kinds: ['API', 'System'] },
|
||||
);
|
||||
|
||||
expect(await processor.preProcessEntity(component, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
});
|
||||
|
||||
expect(await processor.preProcessEntity(api, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'API',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
annotations: {
|
||||
'github.com/project-slug': 'backstage/backstage',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(await processor.preProcessEntity(system, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'System',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
annotations: {
|
||||
'github.com/project-slug': 'backstage/backstage',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('gitlab', () => {
|
||||
it('adds annotation', async () => {
|
||||
|
||||
@@ -31,16 +31,23 @@ const GITLAB_ACTIONS_ANNOTATION = 'gitlab.com/project-slug';
|
||||
/** @public */
|
||||
export class AnnotateScmSlugEntityProcessor implements CatalogProcessor {
|
||||
constructor(
|
||||
private readonly opts: { scmIntegrationRegistry: ScmIntegrationRegistry },
|
||||
private readonly opts: {
|
||||
scmIntegrationRegistry: ScmIntegrationRegistry;
|
||||
kinds?: string[];
|
||||
},
|
||||
) {}
|
||||
|
||||
getProcessorName(): string {
|
||||
return 'AnnotateScmSlugEntityProcessor';
|
||||
}
|
||||
|
||||
static fromConfig(config: Config): AnnotateScmSlugEntityProcessor {
|
||||
static fromConfig(
|
||||
config: Config,
|
||||
options?: { kinds?: string[] },
|
||||
): AnnotateScmSlugEntityProcessor {
|
||||
return new AnnotateScmSlugEntityProcessor({
|
||||
scmIntegrationRegistry: ScmIntegrations.fromConfig(config),
|
||||
kinds: options?.kinds,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,7 +55,13 @@ export class AnnotateScmSlugEntityProcessor implements CatalogProcessor {
|
||||
entity: Entity,
|
||||
location: LocationSpec,
|
||||
): Promise<Entity> {
|
||||
if (entity.kind !== 'Component' || location.type !== 'url') {
|
||||
const applicableKinds = (this.opts.kinds ?? ['Component']).map(k =>
|
||||
k.toLocaleLowerCase('en-US'),
|
||||
);
|
||||
if (
|
||||
!applicableKinds.includes(entity.kind.toLocaleLowerCase('en-US')) ||
|
||||
location.type !== 'url'
|
||||
) {
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user