From 8b048934bcaa9ac0d153471695eadfae7adb9998 Mon Sep 17 00:00:00 2001 From: Iain Billett Date: Thu, 8 Jul 2021 12:33:15 +0100 Subject: [PATCH] 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 --- .changeset/lemon-dancers-taste.md | 9 +++++++++ .../ingestion/processors/codeowners/resolve.test.ts | 2 +- .../src/ingestion/processors/codeowners/resolve.ts | 12 ++++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 .changeset/lemon-dancers-taste.md 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]; }