Skip to content

Commit 5e4831b

Browse files
committed
match * rule
1 parent 7fdfbf7 commit 5e4831b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lua/gh-co/co.lua

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,22 @@ local function buildEscapedPattern(rawPattern)
1010
return string.gsub(rawPattern, "%-", "%%-")
1111
end
1212

13+
-- matches file path substrings
1314
local function isMatch(filePath, pathPattern)
1415
if pathPattern == nil or pathPattern == "" then return false end
1516
if isComment(pathPattern) then return false end
1617

1718
return string.match(filePath, buildEscapedPattern(pathPattern)) ~= nil
1819
end
1920

21+
-- Detects `*` pattern
22+
local function isGlobalMatch(pathPattern)
23+
if pathPattern == nil or pathPattern == "" then return false end
24+
if isComment(pathPattern) then return false end
25+
26+
return string.match(pathPattern, "*") ~= nil
27+
end
28+
2029
local function collectCodeowners(group)
2130
local list = {}
2231

@@ -59,18 +68,21 @@ CO.matchFilesToCodeowner = function(filePaths)
5968
local lines = FS.openCodeownersFileAsLines()
6069

6170
local matches = {}
71+
local globalCodeowners = nil
6272
for line, _, __ in lines do
6373
local split = vim.split(line, " ")
6474
local pathPattern = split[1]
6575

6676
for _, filePath in ipairs(filePaths) do
6777
if isMatch(filePath, pathPattern) then
68-
local codeowners = collectCodeowners(split)
69-
table.insert(matches, { pathPattern = pathPattern, codeowners = codeowners })
78+
table.insert(matches, { pathPattern = pathPattern, codeowners = collectCodeowners(split) })
79+
elseif isGlobalMatch(pathPattern) then
80+
globalCodeowners = collectCodeowners(split)
7081
end
7182
end
7283
end
7384

85+
if #matches == 0 and globalCodeowners ~= nil and #globalCodeowners ~= 0 then return globalCodeowners end
7486
if #matches == 0 then return {} end
7587

7688
sortMatches(matches)

0 commit comments

Comments
 (0)