Update condition before calling normalizeCodeOwner

Update the condition in the ternary operator in the resolveCodeOwner
function to check that match.owners isn't empty before calling
normalizeCodeOwner with match.owners[0]

Before this change normalizeCodeOwner could potentially throw an
error during processing if the `match` object exists but the
match.owners array is empty because normalizeCodeOwner will be passed
`undefined` instead of the string it expects.

Signed-off-by: Isabel Tomb <isabelgtomb@gmail.com>
This commit is contained in:
Isabel Tomb
2024-12-13 16:23:15 -06:00
parent 6b92433d5e
commit 3d475a0ddb
2 changed files with 8 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': patch
---
Updated condition in resolveCodeOwner to fix a bug where normalizeCodeOwner could potentially be called with an invalid arg causing an error in CodeOwnersProcessor.
@@ -30,7 +30,9 @@ export function resolveCodeOwner(
const { filepath } = parseGitUrl(catalogInfoFileUrl);
const match = codeowners.matchFile(filepath, codeOwnerEntries);
return match ? normalizeCodeOwner(match.owners[0]) : undefined;
return match?.owners?.length
? normalizeCodeOwner(match.owners[0])
: undefined;
}
export function normalizeCodeOwner(owner: string) {