Codeowners processor should specify kind for user entities.

The codeowners processor extracts the username of the primary
owner and uses this as the owner field. Given the kind isn't
specified this is assumed to be a group and so the link to
owner in the about card doesn't work. This change specifies
the a kind where the entity is a user. e.g:
`@iain-b` -> `user:iain-b`

Signed-off-by: Iain Billett <iain@roadie.io>
This commit is contained in:
Iain Billett
2021-07-08 12:33:15 +01:00
parent 8f6fbf0232
commit 8b048934bc
3 changed files with 18 additions and 5 deletions
+9
View File
@@ -0,0 +1,9 @@
---
'@backstage/plugin-catalog-backend': patch
---
The codeowners processor extracts the username of the primary owner and uses this as the owner field.
Given the kind isn't specified this is assumed to be a group and so the link to the owner in the about card
doesn't work. This change specifies the kind where the entity is a user. e.g:
`@iain-b` -> `user:iain-b`
@@ -29,7 +29,7 @@ describe('resolveCodeOwner', () => {
describe('normalizeCodeOwner', () => {
it('should remove the @ symbol', () => {
expect(normalizeCodeOwner('@yoda')).toBe('yoda');
expect(normalizeCodeOwner('@yoda')).toBe('user:yoda');
});
it('should remove org from org/team format', () => {
@@ -18,6 +18,10 @@ import * as codeowners from 'codeowners-utils';
import { CodeOwnersEntry } from 'codeowners-utils';
import { filter, get, head, pipe, reverse } from 'lodash/fp';
const USER_PATTERN = /^@.*/;
const GROUP_PATTERN = /^@.*\/.*/;
const EMAIL_PATTERN = /^.*@.*\..*$/;
export function resolveCodeOwner(
contents: string,
pattern = '*',
@@ -35,11 +39,11 @@ export function resolveCodeOwner(
}
export function normalizeCodeOwner(owner: string) {
if (owner.match(/^@.*\/.*/)) {
if (owner.match(GROUP_PATTERN)) {
return owner.split('/')[1];
} else if (owner.match(/^@.*/)) {
return owner.substring(1);
} else if (owner.match(/^.*@.*\..*$/)) {
} else if (owner.match(USER_PATTERN)) {
return `user:${owner.substring(1)}`;
} else if (owner.match(EMAIL_PATTERN)) {
return owner.split('@')[0];
}