Cleanup building FireHydrant service name

Remove the reduntant check for the annotation, and utilize stringifyEntityRef as recommended

Signed-off-by: Dustin Brewer <mannkind@thenullpointer.net>
This commit is contained in:
Dustin Brewer
2023-03-10 15:45:48 +00:00
parent ad4840b0f5
commit 078f46ea32
3 changed files with 7 additions and 8 deletions
@@ -30,7 +30,9 @@ const apis = TestApiRegistry.from([fireHydrantApiRef, mockFireHydrantApi]);
jest.mock('@backstage/plugin-catalog-react', () => ({
useEntity: () => {
return { entity: { metadata: { name: 'service-example' } } };
return {
entity: { kind: 'Component', metadata: { name: 'service-example' } },
};
},
}));
@@ -63,7 +63,7 @@ describe('firehydrant-hooks-getFireHydrantServiceName', () => {
});
it('should return generated service name', () => {
const expected = 'Component:default/test-fh-name';
const expected = 'component:default/test-fh-name';
const e: Entity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
+3 -6
View File
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Entity } from '@backstage/catalog-model';
import { Entity, stringifyEntityRef } from '@backstage/catalog-model';
export const FIREHYDRANT_SERVICE_NAME_ANNOTATION =
'firehydrant.com/service-name';
@@ -21,8 +21,5 @@ export const FIREHYDRANT_SERVICE_NAME_ANNOTATION =
export const isFireHydrantAvailable = (entity: Entity) =>
Boolean(entity.metadata.annotations?.[FIREHYDRANT_SERVICE_NAME_ANNOTATION]);
export const getFireHydrantServiceName = (entity: Entity) =>
isFireHydrantAvailable(entity)
? entity?.metadata.annotations?.[FIREHYDRANT_SERVICE_NAME_ANNOTATION] ?? ''
: `${entity?.kind}:${entity?.metadata?.namespace ?? 'default'}/${
entity?.metadata?.name
}`;
entity?.metadata.annotations?.[FIREHYDRANT_SERVICE_NAME_ANNOTATION] ??
stringifyEntityRef(entity);