Skip to content

Commit

Permalink
feat: if no specified owner, fallback to default codeowner
Browse files Browse the repository at this point in the history
  • Loading branch information
devindford committed Aug 6, 2024
1 parent 9527cb8 commit 8b31fd5
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions .github/workflows/codeowner_review_status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,25 @@ jobs:
if (pattern.endsWith('/')) {
return file.startsWith(pattern);
}
// Handle glob patterns
let regexPattern = pattern
.replace(/\./g, '\\.')
.replace(/\*/g, '[^/]*')
.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);
};
Expand All @@ -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));
Expand Down

0 comments on commit 8b31fd5

Please sign in to comment.