From c0d0e2bccb4fe26b79d220b2ed8d99e3499b3948 Mon Sep 17 00:00:00 2001 From: LvffY Date: Sat, 2 Apr 2022 15:39:17 +0200 Subject: [PATCH] =?UTF-8?q?[#10582]=20=F0=9F=90=9B=20Use=20getEntitySource?= =?UTF-8?q?Location=20instead=20of=20custom=20method=20to=20get=20the=20en?= =?UTF-8?q?tity=20source=20URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: LvffY (cherry picked from commit f0e86e8ba349cf7056c64960b7ad39740dad4cf6) --- .../src/service/TodoReaderService.ts | 39 +------------------ 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/plugins/todo-backend/src/service/TodoReaderService.ts b/plugins/todo-backend/src/service/TodoReaderService.ts index 4397f34045..1b3376dbfd 100644 --- a/plugins/todo-backend/src/service/TodoReaderService.ts +++ b/plugins/todo-backend/src/service/TodoReaderService.ts @@ -17,10 +17,7 @@ import { InputError, NotFoundError } from '@backstage/errors'; import { CatalogApi } from '@backstage/catalog-client'; import { - ANNOTATION_LOCATION, - ANNOTATION_SOURCE_LOCATION, - Entity, - parseLocationRef, + getEntitySourceLocation, stringifyEntityRef, } from '@backstage/catalog-model'; import { TodoReader } from '../lib'; @@ -75,7 +72,7 @@ export class TodoReaderService implements TodoService { ); } - const url = this.getEntitySourceUrl(entity); + const url = getEntitySourceLocation(entity).target; const todos = await this.todoReader.readTodos({ url }); let limit = req.limit ?? this.defaultPageSize; @@ -125,36 +122,4 @@ export class TodoReaderService implements TodoService { limit, }; } - - private getEntitySourceUrl(entity: Entity) { - const sourceLocation = - entity.metadata.annotations?.[ANNOTATION_SOURCE_LOCATION]; - if (sourceLocation) { - const parsed = parseLocationRef(sourceLocation); - if (parsed.type !== 'url') { - throw new InputError( - `Invalid entity source location type for ${stringifyEntityRef( - entity, - )}, got '${parsed.type}'`, - ); - } - return parsed.target; - } - - const location = entity.metadata.annotations?.[ANNOTATION_LOCATION]; - if (location) { - const parsed = parseLocationRef(location); - if (parsed.type !== 'url') { - throw new InputError( - `Invalid entity location type for ${stringifyEntityRef( - entity, - )}, got '${parsed.type}'`, - ); - } - return parsed.target; - } - throw new InputError( - `No entity location annotation found for ${stringifyEntityRef(entity)}`, - ); - } }