From 8b048934bcaa9ac0d153471695eadfae7adb9998 Mon Sep 17 00:00:00 2001 From: Iain Billett Date: Thu, 8 Jul 2021 12:33:15 +0100 Subject: [PATCH 1/3] 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]; } From e1f97de0531c081bd57e755950e8fc0ac1daf53b Mon Sep 17 00:00:00 2001 From: Iain Billett Date: Thu, 8 Jul 2021 15:02:26 +0100 Subject: [PATCH 2/3] Update plugins/catalog-backend/src/ingestion/processors/codeowners/resolve.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fredrik Adelöw Signed-off-by: Iain Billett --- .../src/ingestion/processors/codeowners/resolve.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/catalog-backend/src/ingestion/processors/codeowners/resolve.ts b/plugins/catalog-backend/src/ingestion/processors/codeowners/resolve.ts index 0fe69fab97..00645f0c9d 100644 --- a/plugins/catalog-backend/src/ingestion/processors/codeowners/resolve.ts +++ b/plugins/catalog-backend/src/ingestion/processors/codeowners/resolve.ts @@ -42,7 +42,7 @@ export function normalizeCodeOwner(owner: string) { if (owner.match(GROUP_PATTERN)) { return owner.split('/')[1]; } else if (owner.match(USER_PATTERN)) { - return `user:${owner.substring(1)}`; + return `User:${owner.substring(1)}`; } else if (owner.match(EMAIL_PATTERN)) { return owner.split('@')[0]; } From fa6a5c025d9c384bdccd55267e32d1e0838b85da Mon Sep 17 00:00:00 2001 From: Iain Billett Date: Thu, 8 Jul 2021 15:47:19 +0100 Subject: [PATCH 3/3] Typo Signed-off-by: Iain Billett --- .../src/ingestion/processors/codeowners/resolve.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9e1893e4b1..4e6c646073 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('user:yoda'); + expect(normalizeCodeOwner('@yoda')).toBe('User:yoda'); }); it('should remove org from org/team format', () => {