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

feat(config/validation): validate options which support regex/glob matching #28693

Merged
merged 14 commits into from May 5, 2024

Conversation

RahulGautamSingh
Copy link
Collaborator

@RahulGautamSingh RahulGautamSingh commented Apr 26, 2024

Changes

  • Add new fields patternMatch to the config options, which will be used to identify options which support regex/glob matching
  • Refactor validation logic
  • Add validation for options which support regex/Glob matching. This validation logic ensures that the options do not contain * or ** values along with other values.

Example: (these are not ok)

 "matchRepositories": ["*", "!abc/def"]
  "matchRepositories": ["*", "x/y", "!abc/def"]
  "matchRepositories": ["*", "x/y"]
  "matchRepositories": ["*", "**"]

Context

Closes: #28554

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@RahulGautamSingh RahulGautamSingh requested review from rarkins, HonkingGoose and viceice and removed request for HonkingGoose April 26, 2024 18:10
lib/config/types.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@HonkingGoose HonkingGoose left a comment

Choose a reason for hiding this comment

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

This new field needs to be explained in the docs. Right now it only shows the field in the config options table.

@RahulGautamSingh
Copy link
Collaborator Author

This new field needs to be explained in the docs. Right now it only shows the field in the config options table.

What place should this be added to?

@secustor
Copy link
Collaborator

secustor commented Apr 26, 2024

This new field needs to be explained in the docs. Right now it only shows the field in the config options table.

This is not exposed to users, but rather for internal use to identify options which support the pattern matching feature.

Later this can be used to automatically link from these user exposed options to our "pattern matching" docs

@RahulGautamSingh
Copy link
Collaborator Author

RahulGautamSingh commented Apr 26, 2024

The docs part needs to have some discussion so I will keep this option only for internal use in context of the issue this is PR is related to.

Copy link
Collaborator

@rarkins rarkins left a comment

Choose a reason for hiding this comment

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

Needs validation added

lib/config/types.ts Outdated Show resolved Hide resolved
lib/config/validation-helpers/regex-glob-matchers.spec.ts Outdated Show resolved Hide resolved
lib/config/validation.ts Outdated Show resolved Hide resolved
lib/config/validation-helpers/regex-glob-matchers.ts Outdated Show resolved Hide resolved
tools/docs/config.ts Show resolved Hide resolved
lib/config/validation.ts Outdated Show resolved Hide resolved
@RahulGautamSingh RahulGautamSingh changed the title feat(config): regexOrGlob feat(config): patternMatch May 1, 2024
@RahulGautamSingh RahulGautamSingh changed the title feat(config): patternMatch feat(config/options): add patternMatch field May 1, 2024
@RahulGautamSingh RahulGautamSingh changed the title feat(config/options): add patternMatch field feat(config/validation): validate options which support regex/glob matching May 1, 2024
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
secustor
secustor previously approved these changes May 1, 2024
Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

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

otherwise lgtm

lib/config/validation.ts Show resolved Hide resolved
lib/config/validation.ts Outdated Show resolved Hide resolved
viceice
viceice previously approved these changes May 3, 2024
secustor
secustor previously approved these changes May 3, 2024
Copy link
Collaborator

@rarkins rarkins left a comment

Choose a reason for hiding this comment

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

Can we combine this with other checks that validate the regex is ok?

@RahulGautamSingh
Copy link
Collaborator Author

Can we combine this with other checks that validate the regex is ok?

We have two checks for regex.

  1. isRegexMatch combined with getRegexPredicate, which is used to validation the regex for options of type:string
  2. matchRegexOrGlobList which is used to check whether theenv key names & hostRules.headers set in repo config match the patterns present in allowedEnv & allowedHeaders from the admin config resp.

For check(1), there isn't any way to combine as it only checks for regex validation only, no glob matching and it is designed for single string rather than an array

For check(2), we could make it work if we modify fn to include an if-check for the * or ** logic and expand the return types, to include an extra field say errMsg which we can use to know about the error.

For eg.
Currently the matchRegexOrGlobList fn returns a boolean

export function matchRegexOrGlobList(
input: string,
patterns: string[],
): boolean {

true: if the key is matches the patterns
false: if no match is found or patterns list is empty

New return types:

export function matchRegexOrGlobList(
  input: string,
  patterns: string[],
  currentPath?: string,
): { res: boolean; errMsg?: string } 

Incase we encounter an error say no matc found or * or ** string combined with other patterns, we pass it using the errMsg field and it can be then used in the validation logic.

@rarkins rarkins dismissed stale reviews from secustor and viceice via 9bc85f9 May 5, 2024 07:14
@rarkins
Copy link
Collaborator

rarkins commented May 5, 2024

@RahulGautamSingh I pushed my suggested change to this branch - wdyt?

@RahulGautamSingh
Copy link
Collaborator Author

RahulGautamSingh commented May 5, 2024

@RahulGautamSingh I pushed my suggested change to this branch - wdyt?

Looks good. I had misunderstood your ask a fair bit :)

@rarkins rarkins requested review from secustor and viceice May 5, 2024 07:24
Co-authored-by: RahulGautamSingh <rahultesnik@gmail.com>
@rarkins rarkins added this pull request to the merge queue May 5, 2024
Merged via the queue into renovatebot:main with commit 265e628 May 5, 2024
37 checks passed
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 37.341.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

Throw config validation error if combining * with other values in a matchRegexOrGlobList field
6 participants