From 301bd669197a81ff96d357744ae6d90162da9cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Mon, 30 Mar 2020 14:24:22 +0200 Subject: [PATCH] [cli] CODEOWNERS: catch-all goes first, and paths are absolute --- packages/cli/src/commands/create-plugin/createPlugin.ts | 2 +- packages/cli/src/commands/create-plugin/lib/codeowners.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/create-plugin/createPlugin.ts b/packages/cli/src/commands/create-plugin/createPlugin.ts index 4d264b01f9..da695bee95 100644 --- a/packages/cli/src/commands/create-plugin/createPlugin.ts +++ b/packages/cli/src/commands/create-plugin/createPlugin.ts @@ -405,7 +405,7 @@ const createPlugin = async () => { if (ownerIds && ownerIds.length) { await addCodeownersEntry( codeownersPath!, - path.join('plugins', answers.id), + `/plugins/${answers.id}`, ownerIds, ); } diff --git a/packages/cli/src/commands/create-plugin/lib/codeowners.ts b/packages/cli/src/commands/create-plugin/lib/codeowners.ts index 1ffa640f04..91b0e19782 100644 --- a/packages/cli/src/commands/create-plugin/lib/codeowners.ts +++ b/packages/cli/src/commands/create-plugin/lib/codeowners.ts @@ -20,6 +20,7 @@ import path from 'path'; const TEAM_ID_RE = /^@[-\w]+\/[-\w]+$/; const USER_ID_RE = /^@[-\w]+$/; const EMAIL_RE = /^[^@]+@[-.\w]+\.[-\w]+$/i; +const DEFAULT_OWNER = '@spotify/backstage-core'; type CodeownersEntry = { ownedPath: string; @@ -96,8 +97,11 @@ export async function addCodeownersEntry( const newDeclarationEntries = oldDeclarationEntries .filter(entry => entry.ownedPath !== '*') .concat([{ ownedPath, ownerIds }]) - .sort((l1, l2) => l1.ownedPath.localeCompare(l2.ownedPath)) - .concat([{ ownedPath: '*', ownerIds: ['@spotify/backstage-core'] }]); + .sort((l1, l2) => l1.ownedPath.localeCompare(l2.ownedPath)); + newDeclarationEntries.unshift({ + ownedPath: '*', + ownerIds: [DEFAULT_OWNER], + }); // Calculate longest path to be able to align entries nicely const longestOwnedPath = newDeclarationEntries.reduce(