fix not to add git commit link in about card edit button
Signed-off-by: npiyush97 <npiyush35@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': patch
|
||||
---
|
||||
|
||||
Added a regex test to check commit hash.If url is from git commit branch ignore the edit url.
|
||||
@@ -166,5 +166,53 @@ describe('AnnotateLocationEntityProcessor', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
it('should not render edit button in about for invalid or git hash commit branch', async () => {
|
||||
const entity: Entity = {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
},
|
||||
};
|
||||
|
||||
const location: LocationSpec = {
|
||||
type: 'url',
|
||||
target:
|
||||
'https://github.com/backstage/backstage/blob/f1ba2bc6097a757c2827ff97fa301cff626de137/packages/app/catalog-info.yaml',
|
||||
};
|
||||
const originLocation: LocationSpec = {
|
||||
type: 'url',
|
||||
target:
|
||||
'https://github.com/backstage/backstage/blob/f1ba2bc6097a757c2827ff97fa301cff626de137/catalog-info.yaml',
|
||||
};
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(new ConfigReader({}));
|
||||
const processor = new AnnotateLocationEntityProcessor({ integrations });
|
||||
|
||||
expect(
|
||||
await processor.preProcessEntity(
|
||||
entity,
|
||||
location,
|
||||
() => {},
|
||||
originLocation,
|
||||
),
|
||||
).toEqual({
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-component',
|
||||
annotations: {
|
||||
'backstage.io/managed-by-location':
|
||||
'url:https://github.com/backstage/backstage/blob/f1ba2bc6097a757c2827ff97fa301cff626de137/packages/app/catalog-info.yaml',
|
||||
'backstage.io/managed-by-origin-location':
|
||||
'url:https://github.com/backstage/backstage/blob/f1ba2bc6097a757c2827ff97fa301cff626de137/catalog-info.yaml',
|
||||
'backstage.io/view-url':
|
||||
'https://github.com/backstage/backstage/blob/f1ba2bc6097a757c2827ff97fa301cff626de137/packages/app/catalog-info.yaml',
|
||||
'backstage.io/source-location':
|
||||
'url:https://github.com/backstage/backstage/tree/f1ba2bc6097a757c2827ff97fa301cff626de137/packages/app/',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -53,12 +53,16 @@ export class AnnotateLocationEntityProcessor implements CatalogProcessor {
|
||||
let viewUrl;
|
||||
let editUrl;
|
||||
let sourceLocation;
|
||||
const gitCommitBranchURLPattern = /\b[0-9a-f]{5,40}\b/;
|
||||
|
||||
if (location.type === 'url') {
|
||||
const scmIntegration = integrations.byUrl(location.target);
|
||||
|
||||
viewUrl = location.target;
|
||||
editUrl = scmIntegration?.resolveEditUrl(location.target);
|
||||
|
||||
if (!gitCommitBranchURLPattern.test(location.target)) {
|
||||
editUrl = scmIntegration?.resolveEditUrl(location.target);
|
||||
}
|
||||
|
||||
const sourceUrl = scmIntegration?.resolveUrl({
|
||||
url: './',
|
||||
|
||||
Reference in New Issue
Block a user