Merge pull request #6398 from RoadieHQ/fix-codeowners-processor-user-entity-ref
Codeowners processor should specify kind for user entities.
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user