From 0f9a61e4cac057d00eb71a853328a1b1fc7092bd Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Wed, 7 Oct 2020 09:40:17 +0200
Subject: [PATCH] logs: add CODEOWNERS debug

---
 lib/workers/pr/code-owners.ts | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/workers/pr/code-owners.ts b/lib/workers/pr/code-owners.ts
index c6efc89d9a..4d0f28991a 100644
--- a/lib/workers/pr/code-owners.ts
+++ b/lib/workers/pr/code-owners.ts
@@ -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 [];
   }
 }
-- 
GitLab