[cli] CODEOWNERS: catch-all goes first, and paths are absolute

This commit is contained in:
Fredrik Adelöw
2020-03-30 14:24:22 +02:00
parent 88a6b3d7c4
commit 301bd66919
2 changed files with 7 additions and 3 deletions
@@ -405,7 +405,7 @@ const createPlugin = async () => {
if (ownerIds && ownerIds.length) {
await addCodeownersEntry(
codeownersPath!,
path.join('plugins', answers.id),
`/plugins/${answers.id}`,
ownerIds,
);
}
@@ -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(