Make source source-location has the format of a location ref
Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
+3
-3
@@ -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',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -81,7 +81,7 @@ describe('<AboutCard />', () => {
|
||||
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: {
|
||||
|
||||
@@ -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: <ScmIntegrationIcon type={entitySourceLocation?.type} />,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user