Skip to content
Snippets Groups Projects
Unverified Commit edacf84f authored by Erin's avatar Erin Committed by GitHub
Browse files

feat(codeowners): ignore inline comments in a CODEOWNERS file (#23996)

parent c858840f
No related branches found
No related tags found
No related merge requests found
......@@ -219,9 +219,9 @@ describe('workers/repository/update/pr/code-owners', () => {
[
'# comment line',
' \t ',
' * @jimmy ',
' * @jimmy # inline comment ',
' # comment line with leading whitespace',
' package.json @john @maria ',
' package.json @john @maria#inline comment without leading whitespace ',
].join('\n')
);
git.getBranchFiles.mockResolvedValueOnce(['package.json']);
......
import is from '@sindresorhus/is';
import ignore from 'ignore';
import { logger } from '../../../../logger';
import type { Pr } from '../../../../modules/platform';
......@@ -102,9 +103,11 @@ export async function codeOwnersForPr(pr: Pr): Promise<string[]> {
// Convert CODEOWNERS file into list of matching rules
const fileOwnerRules = codeOwnersFile
.split(newlineRegex)
// Remove empty and commented lines
// Remove comments
.map((line) => line.split('#')[0])
// Remove empty lines
.map((line) => line.trim())
.filter((line) => line && !line.startsWith('#'))
.filter(is.nonEmptyString)
// Extract pattern & usernames
.map(extractOwnersFromLine);
......
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