From 8b31fd5e2404606f96b36878f68bc5a054017fb3 Mon Sep 17 00:00:00 2001 From: Devin Ford Date: Tue, 6 Aug 2024 14:44:56 -0400 Subject: [PATCH] feat: if no specified owner, fallback to default codeowner --- .github/workflows/codeowner_review_status.yml | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/codeowner_review_status.yml b/.github/workflows/codeowner_review_status.yml index cafeb376ab864..6fc8d252d3676 100644 --- a/.github/workflows/codeowner_review_status.yml +++ b/.github/workflows/codeowner_review_status.yml @@ -58,7 +58,7 @@ jobs: if (pattern.endsWith('/')) { return file.startsWith(pattern); } - + // Handle glob patterns let regexPattern = pattern .replace(/\./g, '\\.') @@ -66,17 +66,17 @@ jobs: .replace(/\?/g, '[^/]') .replace(/\//g, '\\/') .replace(/\*\*/g, '.*'); - + // For double-star patterns, match any depth if (pattern.includes('**')) { return new RegExp(`^${regexPattern}`).test(file); } - + // For patterns without wildcards, check if the file is in the directory or is the file itself if (!pattern.includes('*') && !pattern.includes('?')) { return file === pattern || file.startsWith(pattern + '/'); } - + // For single-star patterns, don't match across directory boundaries return new RegExp(`^${regexPattern}$`).test(file); }; @@ -86,13 +86,19 @@ jobs: const defaultOwner = codeownersRules.find(rule => rule.pattern === '*')?.owners[0]; files.forEach(file => { let fileOwners = new Set(); + let hasSpecificOwner = false; codeownersRules.forEach(rule => { if (matchesPattern(file.filename, rule.pattern)) { - rule.owners.forEach(owner => fileOwners.add(owner)); + rule.owners.forEach(owner => { + fileOwners.add(owner); + if (rule.pattern !== '*') { + hasSpecificOwner = true; + } + }); } }); - // If no specific owners found, use the default owner - if (fileOwners.size === 0 && defaultOwner) { + // If no specific owners found or only the default owner was found, use the default owner + if (!hasSpecificOwner && defaultOwner) { fileOwners.add(defaultOwner); } fileOwners.forEach(owner => relevantOwners.add(owner));