Skip to content

Commit fbdb52e

Browse files
committed
feat(discovery)!: match exclude patterns with picomatch under an owned glob grammar
The exclude discovery filter compiled its own RegExp from each pattern, with "*" the only operator and every other character literal. Each pattern is now compiled once at the input boundary with picomatch (the posix entry, nocase, dot, posix classes, no fast paths, debug), and the boundary owns the grammar: name characters, at most one "/", "*", "?", "[abc]", "[!abc]" or "[^abc]", and one leading "!". Anything else is refused when the inputs are parsed, naming the written pattern, the reason, and the fix, because the pattern is the user's input and because picomatch reads braces, parentheses, quotes, backslashes, a leading "./", and a run of stars as regex syntax through paths no option closes, compiling a wrong or never-matching filter silently. DiscoveryFilters.exclude carries the compiled ExcludePattern (pattern, scope, regex) instead of strings, so a config built from argv still equals one built from the environment, and compileExcludePattern with ExcludePattern join the library surface. The e2e oracle's independent matcher learns "?" and a leading "!", and two scenarios pin the new forms end to end. The upgrading guide gains section 61. BREAKING CHANGE: In an exclude pattern, "?" now matches one character, "[abc]" and "[!abc]" are classes, and a leading "!" negates the pattern; each matched nothing before, so a pattern that relied on one of them matching literally is deleted and one that meant a glob is rewritten in that grammar. A leading "./" (drop it), a run of stars (write one "*"), surrounding whitespace from a library caller (trim it), a "." or ".." side, a second "/", a doubled "!", and any regex token ("(a)+", "\d", "{a..b}", quotes) fail the run naming the fix. Library callers supply exclude as ExcludePattern values from compileExcludePattern instead of strings.
1 parent 3051c79 commit fbdb52e

21 files changed

Lines changed: 890 additions & 48 deletions

‎action.yml‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,15 @@ inputs:
146146
default: ""
147147
exclude:
148148
description: >-
149-
Comma- or newline-separated wildcard patterns removing repositories from
150-
repos: "*" discovery.
149+
Comma- or newline-separated glob patterns removing repositories from
150+
repos: "*" discovery, compared case-insensitively against owner/name
151+
when the pattern has a "/" and against the name alone otherwise. A star
152+
matches any run of characters, "?" one character, "[abc]" one of a set,
153+
"[!abc]" or "[^abc]" one outside it, and one leading "!" negates the
154+
pattern. Beyond those a pattern holds only letters, digits, ".", "-",
155+
and "_", with at most one "/", nothing empty around it, and no side that
156+
is just "." or ".."; anything else (a leading "./", a run of stars, a
157+
regex token such as "(a)+") fails the run naming the fix.
151158
required: false
152159
default: ""
153160
topics:

‎bun.lock‎

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/operate/multi-repo.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ Discovery takes six filter inputs that apply only to `repos: "*"`; setting any o
5757
- `archived` defaults to `skip`, because settings writes fail on archived repositories; `archived: only` is mostly useful with `mode: check`.
5858
- `forks` includes, excludes, or keeps only forks.
5959
- `topics` keeps repositories carrying at least one listed topic, so a single marker topic can opt repositories in. It is unrelated to the `topics` settings section.
60-
- `exclude` takes wildcard patterns where `*` matches anything: a pattern containing `/` is matched against the full `owner/name`, any other against the name alone, case-insensitively.
60+
- `exclude` takes glob patterns, matched case-insensitively: a pattern containing `/` against the full `owner/name`, any other against the name alone.
61+
- `*` matches any run of characters, `?` one character, `[abc]` one of a set, `[!abc]` or `[^abc]` one outside it.
62+
- One leading `!` negates the pattern, so `!svc-*` drops everything except the services.
63+
- Beyond those operators a pattern holds only name characters (letters, digits, `.`, `-`, `_`), at most one `/` with a non-empty glob on each side, and no side that is just `.` or `..`. Anything else (a leading `./`, a run of stars, a brace, a parenthesis, a backslash, a quote, a second `/`, a class holding `*`) fails the run before discovery starts, naming the fix, as does a class like `[z-a]`. The matcher is [picomatch](https://github.com/micromatch/picomatch), confined to that grammar.
6164
- `affiliation` selects which relationships to the token's user qualify, passed to GitHub's `/user/repos` listing: `owner` (the default), `collaborator`, or `organization_member`. The list replaces the default, so widening discovery beyond owned repositories takes `owner,collaborator`.
6265

6366
## Fallback for repositories without a settings file

‎docs/reference/inputs.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ A list input (`sections`, `required-sections`, `repos`, `exclude`, `topics`, `af
3838
| `visibility` | <p>Keeps only repositories of this visibility in repos: "*" discovery: all (default), public, private, or internal.</p> | `false` | `""` |
3939
| `archived` | <p>Archived-repository policy for repos: "*" discovery: skip (default), include, or only.</p> | `false` | `""` |
4040
| `forks` | <p>Fork policy for repos: "*" discovery: include (default), exclude, or only.</p> | `false` | `""` |
41-
| `exclude` | <p>Comma- or newline-separated wildcard patterns removing repositories from repos: "*" discovery.</p> | `false` | `""` |
41+
| `exclude` | <p>Comma- or newline-separated glob patterns removing repositories from repos: "*" discovery, compared case-insensitively against owner/name when the pattern has a "/" and against the name alone otherwise. A star matches any run of characters, "?" one character, "[abc]" one of a set, "[!abc]" or "[^abc]" one outside it, and one leading "!" negates the pattern. Beyond those a pattern holds only letters, digits, ".", "-", and "_", with at most one "/", nothing empty around it, and no side that is just "." or ".."; anything else (a leading "./", a run of stars, a regex token such as "(a)+") fails the run naming the fix.</p> | `false` | `""` |
4242
| `topics` | <p>Comma- or newline-separated topics, of which repos: "*" discovery keeps the repositories carrying at least one.</p> | `false` | `""` |
4343
| `affiliation` | <p>Comma- or newline-separated affiliations for repos: "*" discovery: owner (default), collaborator, or organization_member.</p> | `false` | `""` |
4444
<!-- action-docs-inputs source="action.yml" -->

‎docs/reference/library.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ const renderExitCode = runRender(
246246
| `discoverRepos` | function | The repositories a token can see, filtered |
247247
| `DiscoveryFilters` | type | The filters: `visibility`, `archived`, `forks`, `affiliation`, `topics`, `exclude` |
248248
| `DEFAULT_DISCOVERY_FILTERS` | const | The action's defaults |
249+
| `compileExcludePattern` | function | One `exclude` glob compiled once, or the problem naming why it is unusable and the fix |
250+
| `ExcludePattern` | type | A compiled `exclude` entry: the operator's text, the scope its slash chose, and the regex |
249251
| `parseReposInput` | function | The `repos` input form: slugs, or `"*"` for discovery |
250252
| `resolveCentralTargets` | function | The `<owner>/<name>.yml` files of a repos-dir as targets, with warnings for the files it skipped |
251253
| `dedupeTargets` | function | Merge the central and the remote targets, central first; a remote target whose slug a central one already names is dropped with a notice |

‎docs/upgrading/v2-to-v3.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,12 @@ v3 tryList("/repos/o/r/labels", { perPage: 100 }) // re
12811281

12821282
Fix: add `tryList` to every `GitHubClient` double: answer the pages your `tryRequest` route table would (`per_page=N&page=K` from 1, until a page is short) and return their bodies as `{ data: [...] }`; a client over another transport returns each page's body as received, and honors `until` by stopping after the first page it accepts.
12831283

1284+
## 61. Discovery: `exclude` patterns are globs under an owned grammar
1285+
1286+
For every `repos: "*"` workflow that sets `exclude`, and for `@vivswan/github-settings-as-code` consumers building `DiscoveryFilters`. In v2 an `exclude` pattern knew one operator, `*`, and matched every other character literally, so a `?`, a `[`, or a leading `!` could only ever match nothing. In v3 the pattern is a glob matched by picomatch inside a grammar the input boundary owns: `*` any run of characters, `?` one character, `[abc]` one of a set, `[!abc]` or `[^abc]` one outside it, one leading `!` negating the whole pattern, and beyond those only name characters (letters, digits, `.`, `-`, `_`) with at most one `/`; the scope rule is unchanged (a pattern with `/` matches `owner/name`, any other the name alone, case-insensitively). A pattern that gains glob meaning matched nothing in v2 and matches now: `exclude: "!svc-*"` discovered every repository, and now excludes every one whose name is not `svc-*` (`notice: repos: "*" discovery skipped 2 repositories by exclude pattern "!svc-*": o/tooling, o/website`). A pattern outside the grammar (a leading `./`, a run of stars, a `.` or `..` side, a second `/`, a doubled `!!`, a regex token such as `(a)+`) is your input, so it fails the run before discovery starts, naming every flaw and its fix, never repaired: `exclude: "./tmp-**"` matched nothing in v2 and now exits with `error: the "exclude" input pattern "./tmp-**" is not a usable glob: it starts with "./", which names no owner, so drop every leading "./", and it holds a run of stars, which matches no more than one "*" does, so write one "*". Write ...`.
1287+
1288+
Fix: delete a pattern that relied on `?`, `[`, `]`, or `!` matching literally, since it never matched a repository; rewrite one that meant a glob in the grammar above, following the fix each refusal names. For library callers, `DiscoveryFilters.exclude` takes compiled `ExcludePattern` values instead of strings: run each pattern through `compileExcludePattern` at your input boundary and pass the `Result`'s value.
1289+
12841290
## Order of operations
12851291

12861292
1. Rename any settings file whose path contains a comma, rename `undeclared` to `_undeclared` in every settings file, and move every other underscore key into a YAML comment; the v2 line accepts the old spellings only, so do all three together with the pin move.

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"consola": "3.4.2",
7878
"neverthrow": "8.2.0",
7979
"picocolors": "1.1.1",
80+
"picomatch": "4.0.7",
8081
"yaml": "2.9.1",
8182
"zod": "4.6.5"
8283
},
@@ -90,6 +91,7 @@
9091
"@octokit/openapi-webhooks": "12.1.0",
9192
"@types/bun": "1.4.2",
9293
"@types/node": "26.6.4",
94+
"@types/picomatch": "4.0.3",
9395
"action-docs": "2.5.1",
9496
"ajv": "8.20.0",
9597
"ajv-formats": "3.0.1",

0 commit comments

Comments
 (0)