diff --git a/plugins/catalog-backend/src/ingestion/processors/AnnotateLocationEntityProcessor.test.ts b/plugins/catalog-backend/src/ingestion/processors/AnnotateLocationEntityProcessor.test.ts
index dc138e1487..9c543cdcd4 100644
--- a/plugins/catalog-backend/src/ingestion/processors/AnnotateLocationEntityProcessor.test.ts
+++ b/plugins/catalog-backend/src/ingestion/processors/AnnotateLocationEntityProcessor.test.ts
@@ -66,7 +66,7 @@ describe('AnnotateLocationEntityProcessor', () => {
'backstage.io/edit-url':
'https://github.com/backstage/backstage/edit/master/packages/app/catalog-info.yaml',
'backstage.io/source-location':
- 'https://github.com/backstage/backstage/tree/master/packages/app/',
+ 'url:https://github.com/backstage/backstage/tree/master/packages/app/',
},
},
});
@@ -81,7 +81,7 @@ describe('AnnotateLocationEntityProcessor', () => {
annotations: {
'backstage.io/view-url': 'https://example.com/view',
'backstage.io/edit-url': 'https://example.com/edit',
- 'backstage.io/source-location': 'https://example.com/source',
+ 'backstage.io/source-location': 'url:https://example.com/source',
},
},
};
@@ -119,7 +119,7 @@ describe('AnnotateLocationEntityProcessor', () => {
'url:https://github.com/backstage/backstage/blob/master/catalog-info.yaml',
'backstage.io/view-url': 'https://example.com/view',
'backstage.io/edit-url': 'https://example.com/edit',
- 'backstage.io/source-location': 'https://example.com/source',
+ 'backstage.io/source-location': 'url:https://example.com/source',
},
},
});
diff --git a/plugins/catalog-backend/src/ingestion/processors/AnnotateLocationEntityProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/AnnotateLocationEntityProcessor.ts
index 5b3ed79579..f892055a6a 100644
--- a/plugins/catalog-backend/src/ingestion/processors/AnnotateLocationEntityProcessor.ts
+++ b/plugins/catalog-backend/src/ingestion/processors/AnnotateLocationEntityProcessor.ts
@@ -51,10 +51,18 @@ export class AnnotateLocationEntityProcessor implements CatalogProcessor {
viewUrl = location.target;
editUrl = scmIntegration?.resolveEditUrl(location.target);
- sourceLocation = scmIntegration?.resolveUrl({
+
+ const sourceUrl = scmIntegration?.resolveUrl({
url: './',
base: location.target,
});
+
+ if (sourceUrl) {
+ sourceLocation = stringifyLocationReference({
+ type: 'url',
+ target: sourceUrl,
+ });
+ }
}
return merge(
diff --git a/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx b/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx
index c0552a5be4..926deec325 100644
--- a/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx
+++ b/plugins/catalog/src/components/AboutCard/AboutCard.test.tsx
@@ -81,7 +81,7 @@ describe('', () => {
name: 'software',
annotations: {
'backstage.io/source-location':
- 'https://github.com/backstage/backstage/blob/master/software.yaml',
+ 'url:https://github.com/backstage/backstage/blob/master/software.yaml',
},
},
spec: {
diff --git a/plugins/catalog/src/components/AboutCard/AboutCard.tsx b/plugins/catalog/src/components/AboutCard/AboutCard.tsx
index 407665ce3f..b817eae16f 100644
--- a/plugins/catalog/src/components/AboutCard/AboutCard.tsx
+++ b/plugins/catalog/src/components/AboutCard/AboutCard.tsx
@@ -18,9 +18,14 @@ import {
Entity,
ENTITY_DEFAULT_NAMESPACE,
RELATION_CONSUMES_API,
- RELATION_PROVIDES_API
+ RELATION_PROVIDES_API,
} from '@backstage/catalog-model';
-import { configApiRef, HeaderIconLinkRow, IconLinkVerticalProps, useApi } from '@backstage/core';
+import {
+ configApiRef,
+ HeaderIconLinkRow,
+ IconLinkVerticalProps,
+ useApi,
+} from '@backstage/core';
import { getEntityRelations, useEntity } from '@backstage/plugin-catalog-react';
import {
Card,
@@ -28,7 +33,7 @@ import {
CardHeader,
Divider,
IconButton,
- makeStyles
+ makeStyles,
} from '@material-ui/core';
import DocsIcon from '@material-ui/icons/Description';
import EditIcon from '@material-ui/icons/Edit';
@@ -73,7 +78,7 @@ export function AboutCard({ variant }: AboutCardProps) {
const hasApis =
providesApiRelations.length > 0 || consumesApiRelations.length > 0;
- const viewInSource: IconLinkVerticalProps = {
+ const viewInSource: IconLinkVerticalProps = {
label: 'View Source',
disabled: !entitySourceLocation,
icon: ,
diff --git a/plugins/catalog/src/utils/getEntitySourceLocation.ts b/plugins/catalog/src/utils/getEntitySourceLocation.ts
index 6ea089c312..51d63baf2f 100644
--- a/plugins/catalog/src/utils/getEntitySourceLocation.ts
+++ b/plugins/catalog/src/utils/getEntitySourceLocation.ts
@@ -14,7 +14,11 @@
* limitations under the License.
*/
-import { Entity, SOURCE_LOCATION_ANNOTATION } from '@backstage/catalog-model';
+import {
+ Entity,
+ parseLocationReference,
+ SOURCE_LOCATION_ANNOTATION,
+} from '@backstage/catalog-model';
import { ConfigApi } from '@backstage/core';
import { ScmIntegrations } from '@backstage/integration';
@@ -34,11 +38,16 @@ export function getEntitySourceLocation(
return undefined;
}
- const scmIntegrations = ScmIntegrations.fromConfig(config);
- const integration = scmIntegrations.byUrl(sourceLocation);
+ try {
+ const sourceLocationRef = parseLocationReference(sourceLocation);
+ const scmIntegrations = ScmIntegrations.fromConfig(config);
+ const integration = scmIntegrations.byUrl(sourceLocationRef.target);
- return {
- url: sourceLocation,
- type: integration?.type,
- };
+ return {
+ url: sourceLocationRef.target,
+ type: integration?.type,
+ };
+ } catch {
+ return undefined;
+ }
}