@@ -10,13 +10,22 @@ local function buildEscapedPattern(rawPattern)
10
10
return string.gsub (rawPattern , " %-" , " %%-" )
11
11
end
12
12
13
+ -- matches file path substrings
13
14
local function isMatch (filePath , pathPattern )
14
15
if pathPattern == nil or pathPattern == " " then return false end
15
16
if isComment (pathPattern ) then return false end
16
17
17
18
return string.match (filePath , buildEscapedPattern (pathPattern )) ~= nil
18
19
end
19
20
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
+
20
29
local function collectCodeowners (group )
21
30
local list = {}
22
31
@@ -59,18 +68,21 @@ CO.matchFilesToCodeowner = function(filePaths)
59
68
local lines = FS .openCodeownersFileAsLines ()
60
69
61
70
local matches = {}
71
+ local globalCodeowners = nil
62
72
for line , _ , __ in lines do
63
73
local split = vim .split (line , " " )
64
74
local pathPattern = split [1 ]
65
75
66
76
for _ , filePath in ipairs (filePaths ) do
67
77
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 )
70
81
end
71
82
end
72
83
end
73
84
85
+ if # matches == 0 and globalCodeowners ~= nil and # globalCodeowners ~= 0 then return globalCodeowners end
74
86
if # matches == 0 then return {} end
75
87
76
88
sortMatches (matches )
0 commit comments