File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -116,8 +116,18 @@ CO.matchFilesToCodeowner = function(filePaths)
116
116
117
117
sortMatches (matches )
118
118
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 )
121
131
return codeownersList
122
132
end
123
133
Original file line number Diff line number Diff line change @@ -271,4 +271,23 @@ function TestCO:testDoubleStarLogsPattern() -- luacheck: ignore 212
271
271
lu .assertEquals (result , {" @octocat" })
272
272
end
273
273
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
+
274
293
os.exit (lu .LuaUnit .run ())
You can’t perform that action at this time.
0 commit comments