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

escape globs derived from .codeowner files #106

Merged
merged 6 commits into from
Aug 13, 2024
Merged

Conversation

schoblaska
Copy link
Contributor

@schoblaska schoblaska commented Aug 12, 2024

Globs can contain certain regex characters, like "[" and "]". However, when we are generating a glob from a .codeowners file, we need to escape bracket characters and interpret them literally. Otherwise the resulting glob will not actually match the directory containing the .codeowners file.

Example

file: "/some/[dir]/.codeowner"
unescaped: "/some/[dir]/**/**"
matches: "/some/d/file"
matches: "/some/i/file"
matches: "/some/r/file"
does not match!: "/some/[dir]/file"

@schoblaska schoblaska force-pushed the jms/bracket-ownership branch from 8b99758 to 1fb284d Compare August 12, 2024 20:26
@schoblaska schoblaska marked this pull request as ready for review August 12, 2024 20:26
Copy link
Collaborator

@technicalpickles technicalpickles left a comment

Choose a reason for hiding this comment

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

Globs can contain certain regex characters, like "[" and "]". However, when we are generating a glob from a .codeowners file, we need to escape bracket characters and interpret them literally.

This seems like a potentially breaking change, since it would have been valid been valid to have brackets in globs previously, and now they are changing.

from Dir.glob docs:

[set]
Matches any one character in set. Behaves exactly like character sets in Regexp, including set negation ([^a-z]).

If that is the case, I think this probably needs a major version bump.

Separately... I wonder if it works as expected without this change if you escape filenames in the codeowner file 🤔

@schoblaska
Copy link
Contributor Author

schoblaska commented Aug 13, 2024

@technicalpickles

This seems like a potentially breaking change, since it would have been valid been valid to have brackets in globs previously, and now they are changing.

Are you referring to globs that are defined in a team's config? Those are parsed in a separate mapper and not changed by this PR. You can still use brackets in those globs to define a range of characters, or escape them if you want to match on the bracket characters themselves.

Separately... I wonder if it works as expected without this change if you escape filenames in the codeowner file

This PR affects the ownership method where a .codeowner file containing just the team name indicates "this team owns all the code in this directory (recursively)." There are no filenames to escape in that file, and we need to escape any brackets in the directory because they're part of the path to that file.

Copy link
Collaborator

@technicalpickles technicalpickles left a comment

Choose a reason for hiding this comment

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

Thanks for clarifying 🙇🏻

@schoblaska
Copy link
Contributor Author

Github CODEOWNERS files don't appear to support brackets for ranges of characters. We don't have any special handling for that, so I suspect that using brackets in this gem does not work today.

github/docs#1407 (comment)

@schoblaska schoblaska merged commit 7195411 into main Aug 13, 2024
5 checks passed
@schoblaska schoblaska deleted the jms/bracket-ownership branch August 13, 2024 18:39
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.

Support for .codeowner files within [bracketed] directories
5 participants