nielsbasjes/codeowners

CodeOwners: Missing methods to retrieve the parsed rules

Closed this issue · 10 comments

The library cannot parse the example file provided by GitLab.

It fails with the following error

Unsupported escape character: \#

This seems to be the problem:

# Files with a `#` can still be accessed by escaping the pound sign:
\#file_with_pound.rb @owner-file-with-pound

I know it is explicitly NOT supported by GitHub or Bitbucket, but GitLab officially supports this quirk.

NOTE: I found it also doesn't support another thing - escaped spaces.
I originally thought that's again a GitLab thing but GitHub seems to support that too: https://github.com/orgs/community/discussions/48834

# If the path contains spaces, escape them like this:
path\ with\ spaces/ @space-owner

Sorry, my bad.
I was passing the input as a raw string and didn't escape it properly.
Storing the content in a file and loading it from there seems to work.

I'd appreciate guidance regarding how the API, that is how to use the nl.basjes.codeowners.CodeOwners class.
I can create an instance by passing the input into the constructor but how do I get any useful data out of it?
For instance, I would like to get all the sections but that seems to be inaccessible from outside (or I missed something).

Let's start with the fact that the exact example you referenced is part of the tests
https://github.com/nielsbasjes/codeowners/blob/main/codeowners-reader/src/test/java/nl/basjes/codeowners/TestCodeOwnersGitlab.java#L230

This library already supports the escaping of spaces as documented.
The test to ensure that is here:
https://github.com/nielsbasjes/codeowners/blob/main/codeowners-reader/src/test/java/nl/basjes/codeowners/TestCodeOwnersGitlab.java#L35-L44

This library reads your definition and is then able to answer the question of file ownership as defined in the provided definitions.
You are right that the sections are not in the API you can use. These are just a way of defining file ownership.

I do not yet understand why you would want this available in your application.

Let's start with the fact that the exact example you referenced is part of the tests https://github.com/nielsbasjes/codeowners/blob/main/codeowners-reader/src/test/java/nl/basjes/codeowners/TestCodeOwnersGitlab.java#L230

Yes, sorry again for the initial confusion - as I said, it was an error on my side.

This library reads your definition and is then able to answer the question of file ownership as defined in the provided definitions. You are right that the sections are not in the API you can use. These are just a way of defining file ownership.

I do not yet understand why you would want this available in your application.

I basically need to get the list of all the patterns to support my own tooling.
If this is not intended usage of your library that's fine - I'll try to create my own parser.

I basically need to get the list of all the patterns to support my own tooling.

I can simply add some getters. Let me see what I can do.

@nielsbasjes that looks great.
Thanks a ton for the super-fast turnaround.

Merged

Perfect, thanks!

Released as 1.6.0
Should be in maven central soon