diff --git a/.changeset/twenty-laws-tie.md b/.changeset/twenty-laws-tie.md new file mode 100644 index 0000000000..02e6fca70c --- /dev/null +++ b/.changeset/twenty-laws-tie.md @@ -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` diff --git a/plugins/catalog-backend/src/processors/codeowners/resolve.test.ts b/plugins/catalog-backend/src/processors/codeowners/resolve.test.ts index f9cdf79530..722d27fdb9 100644 --- a/plugins/catalog-backend/src/processors/codeowners/resolve.test.ts +++ b/plugins/catalog-backend/src/processors/codeowners/resolve.test.ts @@ -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', () => { diff --git a/plugins/catalog-backend/src/processors/codeowners/resolve.ts b/plugins/catalog-backend/src/processors/codeowners/resolve.ts index 675f6542aa..b0c44a8797 100644 --- a/plugins/catalog-backend/src/processors/codeowners/resolve.ts +++ b/plugins/catalog-backend/src/processors/codeowners/resolve.ts @@ -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) {