Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codeOwners.getOwners does not bubble up till finding an ownership in CODEOWNER file #104

Closed
doctomansion opened this issue Sep 26, 2024 · 0 comments · Fixed by #105
Closed

Comments

@doctomansion
Copy link

Hi,

Here is the typical piece of code I have in my setup:

{
  name: 'Test',
  eval: ({ codeOwners }) =>
    glob.sync('pattern').flatMap((filePath) => {
      const code = fs.readFileSync(filePath).toString()
      return [
        ...code.matchAll(/regex/gm)
      ].map((match) => {
        const lineNumber = code.substring(0, match.index).split('\n').length
        return {
          filePath,
          text: `${filePath}:${lineNumber}`,
          lineNumber,
          owners: codeOwners.getOwners(filePath),
        }
      })
    }),
}

I'm relying on codeOwners.getOwners(filePath) to set the correct ownership from a CODEOWNER file at the root of the repository.

I observed two things:

  1. I need to prefix filePath with a / for having a match if it's declared in CODEOWNER
  2. The search does not bubble up till finding an ownership. For instance, if CODEOWNER only defines /packages/foo/ @foo, calling codeOwners.getOwners('/packages/foo/bar/john.txt') will return nothing
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 a pull request may close this issue.

1 participant