Skip to content
Snippets Groups Projects
Commit 0f9a61e4 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

logs: add CODEOWNERS debug

parent 67d862d9
No related merge requests found
......@@ -5,6 +5,7 @@ import { readLocalFile } from '../../util/fs';
import { getBranchFiles } from '../../util/git';
export async function codeOwnersForPr(pr: Pr): Promise<string[]> {
logger.debug('Searching for CODEOWNERS file');
try {
const codeOwnersFile =
(await readLocalFile('CODEOWNERS', 'utf8')) ||
......@@ -13,9 +14,12 @@ export async function codeOwnersForPr(pr: Pr): Promise<string[]> {
(await readLocalFile('docs/CODEOWNERS', 'utf8'));
if (!codeOwnersFile) {
logger.debug('No CODEOWNERS file found');
return [];
}
logger.debug(`Found CODEOWNERS file: ${codeOwnersFile}`);
const prFiles = await getBranchFiles(pr.sourceBranch);
const rules = codeOwnersFile
.split('\n')
......@@ -35,11 +39,17 @@ export async function codeOwnersForPr(pr: Pr): Promise<string[]> {
const matchingRule = rules.find((rule) => prFiles?.every(rule.match));
if (!matchingRule) {
logger.debug('No matching CODEOWNERS rule found');
return [];
}
logger.debug(
`CODEOWNERS matched the following usernames: ${JSON.stringify(
matchingRule.usernames
)}`
);
return matchingRule.usernames;
} catch (err) {
logger.warn({ err, pr }, 'Failed to determine code owners for PR.');
logger.warn({ err, pr }, 'Failed to determine CODEOWNERS for PR.');
return [];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment