nielsbasjes / codeowners

A library to use and verify the CODEOWNERS and .gitignore files
Apache License 2.0
5 stars 4 forks source link

CodeOwners: Missing methods to retrieve the parsed rules #109

Closed jumarko closed 3 months ago

jumarko commented 3 months ago

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.

jumarko commented 3 months ago

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
jumarko commented 3 months ago

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).

nielsbasjes commented 3 months ago

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.

jumarko commented 3 months ago

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.

nielsbasjes commented 3 months ago

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 commented 3 months ago

@jumarko Does this do what you are looking for? https://github.com/nielsbasjes/codeowners/pull/111/files

jumarko commented 3 months ago

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

nielsbasjes commented 3 months ago

Merged

jumarko commented 3 months ago

Perfect, thanks!

nielsbasjes commented 3 months ago

Released as 1.6.0 Should be in maven central soon