Skip to content

Commit a68b784

Browse files
committed
test & fix ** pattern with directories
1 parent 1d4285b commit a68b784

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lua/gh-co/co.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,22 @@ end
99
local function buildEscapedPattern(rawPattern)
1010
-- Escape Lua pattern special characters except *
1111
local escaped = string.gsub(rawPattern, "([%-%+%?%(%)])", "%%%1")
12-
-- Convert * to match any character except /
12+
13+
-- Handle ** first (before single *) - use placeholder to avoid conflicts
14+
escaped = string.gsub(escaped, "%*%*", "__DOUBLESTAR__")
15+
16+
-- Convert remaining * to match any character except /
1317
escaped = string.gsub(escaped, "%*", "[^/]*")
1418

19+
-- Replace placeholder with pattern that matches any path including /
20+
escaped = string.gsub(escaped, "__DOUBLESTAR__", ".*")
21+
22+
-- Special handling for **/name patterns - they should match directories
23+
if string.match(rawPattern, "%*%*/[^/]+$") then
24+
-- **/logs should match files within logs directories
25+
escaped = escaped .. "/"
26+
end
27+
1528
-- Handle trailing slash - directory patterns should match everything within
1629
if string.match(escaped, "/$") then
1730
-- Remove trailing slash and match anything that starts with this path

lua/gh-co/co.test.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,19 @@ function TestCO:testRootScriptsDirectoryPattern() -- luacheck: ignore 212
256256
lu.assertEquals(result, {"@doctocat", "@octocat"})
257257
end
258258

259+
function TestCO:testDoubleStarLogsPattern() -- luacheck: ignore 212
260+
-- Test **/logs pattern matches any logs directory at any depth
261+
self.FS.openCodeownersFileAsLines = function()
262+
local lines = {"**/logs @octocat"}
263+
local i = 0
264+
return function()
265+
i = i + 1
266+
return lines[i]
267+
end
268+
end
269+
270+
local result = CO.matchFilesToCodeowner({"build/logs/error.log", "app/server/logs/access.log", "logs/debug.log"})
271+
lu.assertEquals(result, {"@octocat"})
272+
end
273+
259274
os.exit(lu.LuaUnit.run())

0 commit comments

Comments
 (0)