From 9052c3183e11111cc3e5cb91e02d7d3635c0ea3e Mon Sep 17 00:00:00 2001 From: Mark Molinaro <16494982+markjm@users.noreply.github.com> Date: Mon, 27 Jun 2022 22:04:18 +0000 Subject: [PATCH] Ensure we respect inline comments --- CODEOWNERS | 2 +- codeowners.js | 12 ++++++++---- codeowners.test.js | 4 ++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index 152373c..4d6e159 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1 @@ -* @beaugunderson +* @beaugunderson # I own the whole project! diff --git a/codeowners.js b/codeowners.js index 74c4678..e125ee0 100755 --- a/codeowners.js +++ b/codeowners.js @@ -59,13 +59,17 @@ function Codeowners(currentPath, fileName = 'CODEOWNERS') { continue; } - const [pathString, ...usernames] = line.split(/\s+/); + const [data, ...comment] = line.split("#"); + const [pathString, ...usernames] = data.split(/\s+/); - ownerEntries.push({ + const entry = { path: pathString, - usernames, + usernames: usernames.filter(Boolean), match: ownerMatcher(pathString), - }); + } + if(comment && comment.length) entry.comment = comment.join("") + + ownerEntries.push(entry); } // reverse the owner entries to search from bottom to top diff --git a/codeowners.test.js b/codeowners.test.js index e3e3092..17f2e57 100644 --- a/codeowners.test.js +++ b/codeowners.test.js @@ -15,4 +15,8 @@ describe('codeowners', () => { const owner = repos.getOwner(__filename); expect(owner).toEqual(['@beaugunderson']); }); + + it('respects inline comments', () => { + expect(repos.ownerEntries[0].comment).toEqual(" I own the whole project!") + }); });