Skip to content

Commit bf8c52b

Browse files
committed
test & fix left-out codeowners path
1 parent a68b784 commit bf8c52b

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lua/gh-co/co.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,18 @@ CO.matchFilesToCodeowner = function(filePaths)
116116

117117
sortMatches(matches)
118118

119-
local codeownersList = mapCodeowners(matches)
120-
119+
-- Only use the most specific pattern(s) - those with the longest pathPattern
120+
local maxLength = #matches[1].pathPattern
121+
local mostSpecificMatches = {}
122+
for _, match in ipairs(matches) do
123+
if #match.pathPattern == maxLength then
124+
table.insert(mostSpecificMatches, match)
125+
else
126+
break -- Since sorted by length, we can break early
127+
end
128+
end
129+
130+
local codeownersList = mapCodeowners(mostSpecificMatches)
121131
return codeownersList
122132
end
123133

lua/gh-co/co.test.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,23 @@ function TestCO:testDoubleStarLogsPattern() -- luacheck: ignore 212
271271
lu.assertEquals(result, {"@octocat"})
272272
end
273273

274+
function TestCO:testAppsWithEmptyGithubSubdirectory() -- luacheck: ignore 212
275+
-- Test /apps/ with empty /apps/github (no owners)
276+
self.FS.openCodeownersFileAsLines = function()
277+
local lines = {
278+
"/apps/ @octocat",
279+
"/apps/github"
280+
}
281+
local i = 0
282+
return function()
283+
i = i + 1
284+
return lines[i]
285+
end
286+
end
287+
288+
-- Files in /apps/github should have no owners (empty pattern overrides /apps/)
289+
local githubResult = CO.matchFilesToCodeowner({"/apps/github/readme.md"})
290+
lu.assertEquals(githubResult, {})
291+
end
292+
274293
os.exit(lu.LuaUnit.run())

0 commit comments

Comments
 (0)