Merge pull request #28140 from isabeltomb/update-codeownersprocessor-helper

Update CodeOwnersProcessor helper
This commit is contained in:
Ben Lambert
2024-12-23 09:51:28 +01:00
committed by GitHub
3 changed files with 16 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 argument causing an error in `CodeOwnersProcessor`
@@ -46,6 +46,14 @@ describe('resolveCodeOwner', () => {
),
).toBe('team-foo');
});
it('should return undefined if the codeowners file contains no names', () => {
expect(
resolveCodeOwner(
`*`,
'https://github.com/acme/repo/tree/docs/catalog-info.yaml',
),
).toBe(undefined);
});
});
describe('normalizeCodeOwner', () => {
@@ -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) {