Skip to content

Commit

Permalink
feat(config)!: * pattern matches everything (#28556)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed May 19, 2024
1 parent 9049fb2 commit c9c44e4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/usage/string-pattern-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,38 @@ Renovate string matching syntax for some configuration options allows you, as us
- [`minimatch`](https://github.com/isaacs/minimatch) glob patterns, including exact strings matches
- regular expression (regex) patterns

The following fields support this pattern matching:

- `allowedEnv`
- `allowedHeaders`
- `autodiscoverProjects`
- `matchRepositories`

## Special case: Match everything

The value `*` is a special case which means "match everything".
It is not valid to combine `*` with any other positive or negative match.

```json title="Example of valid wildcard use"
{
"allowedEnv": ["*"]
}
```

```json title="Example of invalid wildcard use with additional match"
{
"allowedEnv": ["*", "ABC"]
}
```

```json title="Example of invalid wildcard use with negation"
{
"allowedEnv": ["*", "!ABC"]
}
```

In the latter case, the `*` can be ommitted and achieve the same thing.

## Regex matching

A valid regex pattern:
Expand Down Expand Up @@ -76,6 +108,9 @@ For example, the pattern `["/^abc/", "!/^abcd/", "!/abce/"]`:
- matches `"abc"` and `"abcf"`
- does _not_ match `"foo"`, `"abcd"`, `"abce"`, or `"abcdef"`

If you find yourself in a situation where you need to positive-match a string which starts with `!`, then you need to do so using a regular expression pattern.
For example, `["/^!abc$/"]` will positively match against the string `"!abc"`.

## Usage in Renovate configuration options

Renovate has evolved its approach to string pattern matching over time, but this means that existing configurations may have a mix of approaches and not be entirely consistent with each other.
Expand Down
4 changes: 4 additions & 0 deletions lib/util/string-match.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ describe('util/string-match', () => {
expect(matchRegexOrGlobList('test', ['/test2/'])).toBeFalse();
});

it('returns true if star', () => {
expect(matchRegexOrGlobList('&&&', ['*'])).toBeTrue();
});

it('returns true if any match', () => {
expect(matchRegexOrGlobList('test', ['test', '/test2/'])).toBeTrue();
});
Expand Down
3 changes: 3 additions & 0 deletions lib/util/string-match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export function getRegexOrGlobPredicate(pattern: string): StringMatchPredicate {
}

export function matchRegexOrGlob(input: string, pattern: string): boolean {
if (pattern === '*') {
return true;
}
const predicate = getRegexOrGlobPredicate(pattern);
return predicate(input);
}
Expand Down

0 comments on commit c9c44e4

Please sign in to comment.