Skip to content

Fix CODEOWNERS file search when .github or docs folders are not present#8

Merged
comatory merged 3 commits intocomatory:masterfrom
religiosa1:master
Dec 28, 2025
Merged

Fix CODEOWNERS file search when .github or docs folders are not present#8
comatory merged 3 commits intocomatory:masterfrom
religiosa1:master

Conversation

@religiosa1
Copy link
Contributor

Hey @comatory , thank you for the awesome plugin, really helpful stuff.

That said, I encountered an issue when a repo has docs folder without any CODEOWNERS in it. On init it throws:

plugin/gh-co/gh-co.vim, line 7: Vim(lua):E5108: Error executing lua ...giosa/.local/share/nvim/lazy/gh-co.nvim/lua/gh-co/fs.lua:79: attempt to concatenate local 'githubDirName' (a nil value)
stack trace
Failed to source `/home/religiosa/.local/share/nvim/lazy/gh-co.nvim/plugin/gh-co/gh-co.vim`

vim/_editor.lua:0: /home/religiosa/.config/nvim/init.lua..nvim_exec2() called at /home/religiosa/.config/nvim/init.lua:0[1]../home/religiosa/.local/share/nvim/lazy/gh-co.nvim/plugin/gh-co/gh-co.vim, line 7: Vim(lua):E5108: Error executing lua ...giosa/.local/share/nvim/lazy/gh-co.nvim/lua/gh-co/fs.lua:79: attempt to concatenate local 'githubDirName' (a nil value)
stack traceback:
	...giosa/.local/share/nvim/lazy/gh-co.nvim/lua/gh-co/fs.lua:79: in function 'getCodeownersFilePath'
	...osa/.local/share/nvim/lazy/gh-co.nvim/lua/gh-co/init.lua:115: in function 'init'
	[string ":lua"]:1: in main chunk
	[C]: in function 'nvim_exec2'
	vim/_editor.lua: in function 'cmd'
	...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:510: in function <...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:509>
	[C]: in function 'xpcall'
	.../.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/util.lua:135: in function 'try'
	...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:509: in function 'source'
	...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:457: in function 'source_runtime'
	...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:425: in function 'packadd'
	...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:359: in function '_load'
	...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:197: in function 'load'
	...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:127: in function 'startup'
	...giosa/.local/share/nvim/lazy/lazy.nvim/lua/lazy/init.lua:112: in function 'setup'
	/home/religiosa/.config/nvim/lua/config/lazy.lua:17: in main chunk
	[C]: in function 'require'
	/home/religiosa/.config/nvim/init.lua:2: in main chunk

# stacktrace:
  - vim/_editor.lua:0 _in_ **cmd**
  - ~/.config/nvim/lua/config/lazy.lua:17
  - ~/.config/nvim/init.lua:2

The immediate issue seems to be caused by missed parentheses in the fallback condition in fs.lua:79:

- local codeownerDirName = rootDirName .. "/" .. githubDirName or docsDirName
+ local codeownerDirName = rootDirName .. "/" .. (githubDirName or docsDirName)

Though just adding parenthesis will prevent the error on init, it sill leaves the core functionality broken, if you have CODEOWNERS at root. Also, if we have .github folder without the CODEOWNERS file -- and the file being in either docs or at the root level it won't be picked by the plugin as we don't check for the presence of the file in the .github folder before choosing it.

This PR modifies the behavior of the FS.getCodeownersFilePath so it checks for the CODEOWNERS file presence in the .github foleder, and then root-level, and then docs folders (the order as specified in the Github Docs).

It also adds "CODEOWNERS" to the vim.fs.find arguments in getRootDirectoryName in FS, so we don't miss the cached codeowners file when neither .github nor docs folders are present.

I verified the changes on the local test setup with the following scenarios:

  • just the docs folder present, no CODEOWNERS -- no error thrown on init
  • picking CODEOWENRS from the docs folder when .github folder is also present in the repo
  • picking root-level CODEOWNERS with both .github and docs folders present, either one of them, or none of them
  • picking CODEOWNERS file from docs when .github is both present and not
  • picking CODEOWNERS filr from .github when docs is both present and not

Copy link
Owner

@comatory comatory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @religiosa1 ! Thank you for the contribution and good catch! The plugin shouldn't error like this. I think it's good to remove the assert I had in place just for this reason, as having CODEOWNERS is totally optional.

I am also attaching a patch, I do not have write access to your fork. I think this functionality is pretty important, so I generated unit tests that would check the correct priority for the file lookup. The patch also adds some small changes so the linter can pass.

Would you be OK with applying the patch on your branch?1 I think it would be best to merge it together. I would like to run the pipeline with the patch applied, that should get rid of the failures. Once we add this to master, I will then create a release tag so it can be installed using package managers.

pr-8.patch

Footnotes

  1. Run git apply pr-8.patch locally and push it to your branch 🙏

@religiosa1
Copy link
Contributor Author

Hey @comatory, thanks for the review.
I applied the patch, sorry for the missed linter warning.

@comatory comatory merged commit d7d3492 into comatory:master Dec 28, 2025
1 check passed
@comatory
Copy link
Owner

@religiosa1 thanks for the contribution again. I released the fix in the new 0.0.6 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants