add pattern matching

Signed-off-by: Kiss Miklos <miklos@roadie.io>
This commit is contained in:
Kiss Miklos
2023-01-19 10:26:22 +01:00
parent bb1e4558bd
commit 26ad3398a8
3 changed files with 6 additions and 3 deletions
@@ -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) {
@@ -52,6 +52,7 @@ export async function findCodeOwnerByTarget(
reader: UrlReader,
targetUrl: string,
scmIntegration: ScmIntegration,
pattern: string,
): Promise<string | undefined> {
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;
}
@@ -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'),