diff --git a/plugins/catalog-backend/src/modules/codeowners/CodeOwnersProcessor.ts b/plugins/catalog-backend/src/modules/codeowners/CodeOwnersProcessor.ts index 186b732271..f50ef6b922 100644 --- a/plugins/catalog-backend/src/modules/codeowners/CodeOwnersProcessor.ts +++ b/plugins/catalog-backend/src/modules/codeowners/CodeOwnersProcessor.ts @@ -79,11 +79,13 @@ export class CodeOwnersProcessor implements CatalogProcessor { if (!scmIntegration) { return entity; } - + const pattern = + entity.metadata?.annotations['backstage.io/managed-by-location']; const owner = await findCodeOwnerByTarget( this.reader, location.target, scmIntegration, + pattern, ); if (!owner) { diff --git a/plugins/catalog-backend/src/modules/codeowners/lib/read.ts b/plugins/catalog-backend/src/modules/codeowners/lib/read.ts index 2987e162cc..eae4e7ce91 100644 --- a/plugins/catalog-backend/src/modules/codeowners/lib/read.ts +++ b/plugins/catalog-backend/src/modules/codeowners/lib/read.ts @@ -52,6 +52,7 @@ export async function findCodeOwnerByTarget( reader: UrlReader, targetUrl: string, scmIntegration: ScmIntegration, + pattern: string, ): Promise { const codeownersPaths = scmCodeOwnersPaths[scmIntegration?.type ?? '']; @@ -70,7 +71,7 @@ export async function findCodeOwnerByTarget( return undefined; } - const owner = resolveCodeOwner(contents); + const owner = resolveCodeOwner(contents, pattern); return owner; } diff --git a/plugins/catalog-backend/src/modules/codeowners/lib/resolve.ts b/plugins/catalog-backend/src/modules/codeowners/lib/resolve.ts index 00645f0c9d..f9bc19b1d1 100644 --- a/plugins/catalog-backend/src/modules/codeowners/lib/resolve.ts +++ b/plugins/catalog-backend/src/modules/codeowners/lib/resolve.ts @@ -29,7 +29,7 @@ export function resolveCodeOwner( const owners = codeowners.parse(contents); return pipe( - filter((e: CodeOwnersEntry) => e.pattern === pattern), + filter((e: CodeOwnersEntry) => pattern.includes(e.pattern)), reverse, head, get('owners'),