From 9132deaa768a01ec4259554d8e743a8d7845714e Mon Sep 17 00:00:00 2001 From: alde Date: Mon, 19 Apr 2021 13:58:31 -0400 Subject: [PATCH] fix file content explorer, use getEntitySourceLocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../code-coverage-backend/src/service/router.ts | 14 +++++++++----- .../src/components/FileExplorer/FileContent.tsx | 6 +++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/plugins/code-coverage-backend/src/service/router.ts b/plugins/code-coverage-backend/src/service/router.ts index aba5326f5d..f2e34cd07a 100644 --- a/plugins/code-coverage-backend/src/service/router.ts +++ b/plugins/code-coverage-backend/src/service/router.ts @@ -33,7 +33,11 @@ import { aggregateCoverage, CoverageUtils } from './CoverageUtils'; import { Cobertura } from './converter/cobertura'; import { Jacoco } from './converter/jacoco'; import { Converter } from './converter'; -import { EntityRef, parseEntityName } from '@backstage/catalog-model'; +import { + EntityRef, + getEntitySourceLocation, + parseEntityName, +} from '@backstage/catalog-model'; export interface RouterOptions { config: Config; @@ -127,20 +131,20 @@ export const makeRouter = async ( throw new InputError('Need path query parameter'); } - const sourceLocation = - entityLookup.metadata.annotations?.['backstage.io/source-location']; + const sourceLocation = getEntitySourceLocation(entityLookup); + if (!sourceLocation) { throw new InputError( `No "backstage.io/source-location" annotation on entity ${entity}`, ); } - const vcs = scm.byUrl(sourceLocation); + const vcs = scm.byUrl(sourceLocation.target); if (!vcs) { throw new InputError(`Unable to determine SCM from ${sourceLocation}`); } - const scmTree = await urlReader.readTree(sourceLocation); + const scmTree = await urlReader.readTree(sourceLocation.target); const scmFile = (await scmTree.files()).find(f => f.path === path); if (!scmFile) { res.status(400).json({ diff --git a/plugins/code-coverage/src/components/FileExplorer/FileContent.tsx b/plugins/code-coverage/src/components/FileExplorer/FileContent.tsx index 6844557307..e4ade53f37 100644 --- a/plugins/code-coverage/src/components/FileExplorer/FileContent.tsx +++ b/plugins/code-coverage/src/components/FileExplorer/FileContent.tsx @@ -19,7 +19,7 @@ import { useApi } from '@backstage/core-api'; import { useEntity } from '@backstage/plugin-catalog-react'; import { useAsync } from 'react-use'; import { codeCoverageApiRef } from '../../api'; -import { Progress } from '@backstage/core'; +import { Progress, ResponseErrorPanel } from '@backstage/core'; import { Alert } from '@material-ui/lab'; import { makeStyles, Paper } from '@material-ui/core'; import { highlightLines } from './Highlighter'; @@ -95,11 +95,11 @@ export const FileContent = ({ filename, coverage }: Props) => { return ; } if (error) { - return {error.message}; + return ; } if (!value) { return ( - + Unable to retrieve file content for {filename} );