[#10582] 🐛 Use getEntitySourceLocation instead of custom method to get the entity source URL

Signed-off-by: LvffY <louberger@hotmail.fr>
(cherry picked from commit f0e86e8ba349cf7056c64960b7ad39740dad4cf6)
This commit is contained in:
LvffY
2022-04-02 15:39:17 +02:00
parent 213819c77f
commit c0d0e2bccb
@@ -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)}`,
);
}
}