Skip to content

Commit 06b5151

Browse files
committed
feat!: make wildcard params use simple regex fullmatch
1 parent a81391d commit 06b5151

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ see [configuration](#configuration) below for more.
1717
`https://<filter_url>/1234/ABCDWXYZ` (note: no `/github`) in the GitHub webhook settings:\
1818
![settings](./.github/assets/github-settings.png)
1919
3. Optionally add configuration parameters (see below) to the URL, e.g.
20-
`?allowBranches=master,dev&hideTags=1`.
20+
`?allowBranches=master|dev&hideTags=1`.
2121
4. ????
2222
5. Profit!
2323

2424
## Configuration
2525

2626
Additional options can be configured per URL:
2727

28-
- Only forward events from specific branches (`allowBranches`, simplified wildcard syntax)
29-
- `abc*xyz` is equivalent to `/^(abc.*xyz)$/`
30-
- `stuff,things` is equivalent to `/^(stuff|things)$/`
31-
- `!oh*hi*there` is equivalent to `/^(oh.*hi.*there)$/` inverted
32-
- Ignore tag updates (`hideTags`)
33-
- Ignore burst PR review comments in a short timespan, only showing the first x comments per review
34-
(`commentBurstLimit`)
28+
- `allowBranches`: Only forward events from specific branches
29+
- This is case-sensitive and supports regex
30+
- Only full matches are considered, i.e. no substrings; `abc.*xyz` is equivalent to
31+
`/^(abc.*xyz)$/`
32+
- `hideTags`: Ignore tag updates
33+
- `commentBurstLimit`: Ignore burst PR review comments in a short timespan, only showing the first x
34+
comments per review

src/util.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,12 @@ export function sleep(ms: number): Promise<void> {
88
return new Promise((resolve) => setTimeout(resolve, ms));
99
}
1010

11-
function _escapeRegex(pattern: string): string {
12-
return pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
13-
}
14-
1511
export function wildcardMatch(pattern: string, target: string): boolean {
1612
let invert = false;
1713
if (pattern[0] === "!") {
1814
invert = true;
1915
pattern = pattern.slice(1);
2016
}
21-
22-
// allow `*` wildcard specifier, translate to `.*` regex;
23-
// escape everything else
24-
pattern = pattern.split("*").map(_escapeRegex).join(".*");
25-
// treat `,` as `|`
26-
pattern = pattern.replaceAll(",", "|");
2717
// add anchors
2818
pattern = `^(${pattern})$`;
2919

0 commit comments

Comments
 (0)