added utility to remove backstage entity refs from entities

Signed-off-by: Phred <fearphage@gmail.com>
This commit is contained in:
Phred
2023-03-27 11:59:38 -05:00
parent ef50084b89
commit 8f0bd33d7a
2 changed files with 24 additions and 1 deletions
@@ -15,7 +15,12 @@
*/
import { Git, getVoidLogger } from '@backstage/backend-common';
import { commitAndPushRepo, initRepoAndPush } from './helpers';
import { entityNamePickerValidation } from '@backstage/plugin-scaffolder/src/components/fields/EntityNamePicker';
import {
commitAndPushRepo,
familiarizeEntityName,
initRepoAndPush,
} from './helpers';
jest.mock('@backstage/backend-common', () => ({
Git: {
@@ -301,3 +306,17 @@ describe('commitAndPushRepo', () => {
});
});
});
describe('familiarizeEntityName', () => {
it.each([
'user:default/catpants',
'group:default/catpants',
'user:catpants',
'default/catpants',
'user:custom/catpants',
'group:custom/catpants',
'catpants',
])('should parse: "%s"', (entityName: string) => {
expect(familiarizeEntityName(entityName)).toEqual('catpants');
});
});
@@ -296,3 +296,7 @@ export function getGitCommitMessage(
? gitCommitMessage
: config.getOptionalString('scaffolder.defaultCommitMessage');
}
export function familiarizeEntityName(name: string): string {
return name.replace(/^.*[:/]/g, '');
}