Merge pull request #19412 from taraknath555/azure-devops/fetch-project-repo
Adding azure case in AnnotateScmSlugEntityProcessor
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': minor
|
||||
---
|
||||
|
||||
set azure annotation `dev.azure.com/project-repo` in `AnnotateScmSlugEntityProcessor` to find the project and repo information for the repos that contains `dev.azure.com` in the url
|
||||
@@ -268,4 +268,163 @@ describe('AnnotateScmSlugEntityProcessor', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('azure', () => {
|
||||
it('adds annotation', async () => {
|
||||
const entity: Entity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
};
|
||||
const location: LocationSpec = {
|
||||
type: 'url',
|
||||
target:
|
||||
'https://dev.azure.com/organization/project/_git/repository?path=%2Fcatalog-info.yaml',
|
||||
};
|
||||
|
||||
const processor = AnnotateScmSlugEntityProcessor.fromConfig(
|
||||
new ConfigReader({}),
|
||||
);
|
||||
|
||||
expect(await processor.preProcessEntity(entity, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
annotations: {
|
||||
'dev.azure.com/project-repo': 'project/repository',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('does not override existing annotation', async () => {
|
||||
const entity: Entity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
annotations: {
|
||||
'dev.azure.com/project-repo': 'myproj/myrepo',
|
||||
},
|
||||
},
|
||||
};
|
||||
const location: LocationSpec = {
|
||||
type: 'url',
|
||||
target:
|
||||
'https://dev.azure.com/organization/project/_git/repository?path=%2Fcatalog-info.yaml',
|
||||
};
|
||||
|
||||
const processor = AnnotateScmSlugEntityProcessor.fromConfig(
|
||||
new ConfigReader({}),
|
||||
);
|
||||
|
||||
expect(await processor.preProcessEntity(entity, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
annotations: {
|
||||
'dev.azure.com/project-repo': 'myproj/myrepo',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should not add annotation for other providers', async () => {
|
||||
const entity: Entity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
};
|
||||
const location: LocationSpec = {
|
||||
type: 'url',
|
||||
target:
|
||||
'https://not-in-mock-config.example.com/backstage/backstage/-/blob/master/catalog-info.yaml',
|
||||
};
|
||||
|
||||
const processor = AnnotateScmSlugEntityProcessor.fromConfig(
|
||||
new ConfigReader({}),
|
||||
);
|
||||
|
||||
expect(await processor.preProcessEntity(entity, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
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://dev.azure.com/organization/project/_git/repository?path=%2Fcatalog-info.yaml',
|
||||
};
|
||||
|
||||
const processor = AnnotateScmSlugEntityProcessor.fromConfig(
|
||||
new ConfigReader({}),
|
||||
{ kinds: ['API', 'Component'] },
|
||||
);
|
||||
|
||||
expect(await processor.preProcessEntity(component, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
annotations: {
|
||||
'dev.azure.com/project-repo': 'project/repository',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(await processor.preProcessEntity(api, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'API',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
annotations: {
|
||||
'dev.azure.com/project-repo': 'project/repository',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(await processor.preProcessEntity(system, location)).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'System',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,6 +27,7 @@ import { CatalogProcessor } from '@backstage/plugin-catalog-node';
|
||||
|
||||
const GITHUB_ACTIONS_ANNOTATION = 'github.com/project-slug';
|
||||
const GITLAB_ACTIONS_ANNOTATION = 'gitlab.com/project-slug';
|
||||
const AZURE_ACTIONS_ANNOTATION = 'dev.azure.com/project-repo';
|
||||
|
||||
/** @public */
|
||||
export class AnnotateScmSlugEntityProcessor implements CatalogProcessor {
|
||||
@@ -81,6 +82,9 @@ export class AnnotateScmSlugEntityProcessor implements CatalogProcessor {
|
||||
case 'gitlab':
|
||||
annotation = GITLAB_ACTIONS_ANNOTATION;
|
||||
break;
|
||||
case 'azure':
|
||||
annotation = AZURE_ACTIONS_ANNOTATION;
|
||||
break;
|
||||
default:
|
||||
return entity;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user