diff --git a/.changeset/lemon-dancers-taste.md b/.changeset/lemon-dancers-taste.md new file mode 100644 index 0000000000..0542fe4a54 --- /dev/null +++ b/.changeset/lemon-dancers-taste.md @@ -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` diff --git a/plugins/catalog-backend/src/ingestion/processors/codeowners/resolve.test.ts b/plugins/catalog-backend/src/ingestion/processors/codeowners/resolve.test.ts index ccf4493dc6..9e1893e4b1 100644 --- a/plugins/catalog-backend/src/ingestion/processors/codeowners/resolve.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/codeowners/resolve.test.ts @@ -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', () => { diff --git a/plugins/catalog-backend/src/ingestion/processors/codeowners/resolve.ts b/plugins/catalog-backend/src/ingestion/processors/codeowners/resolve.ts index 886f3160b3..0fe69fab97 100644 --- a/plugins/catalog-backend/src/ingestion/processors/codeowners/resolve.ts +++ b/plugins/catalog-backend/src/ingestion/processors/codeowners/resolve.ts @@ -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]; }