-
Notifications
You must be signed in to change notification settings - Fork 352
Fix qmd: multi-pattern checkouts index 0 files due to comma-joined patterns #22673
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,30 @@ function resolveEnvVars(p) { | |||||||||||
| return p.replace(/\$\{([^}]+)\}/g, (_, name) => process.env[name] || ""); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Counts files matching a glob pattern in basePath using the Node.js 22+ built-in | ||||||||||||
| * `fs.globSync`. Returns null when the API is unavailable (older Node.js) or an error | ||||||||||||
| * occurs, so callers can treat the count as unknown and log accordingly. | ||||||||||||
| * @param {string} basePath | ||||||||||||
| * @param {string} pattern | ||||||||||||
| * @returns {number | null} | ||||||||||||
| */ | ||||||||||||
| function countGlobMatches(basePath, pattern) { | ||||||||||||
| try { | ||||||||||||
| const { globSync } = require("node:fs"); | ||||||||||||
| if (typeof globSync !== "function") return null; | ||||||||||||
| const files = globSync(pattern, { cwd: basePath }); | ||||||||||||
| return Array.isArray(files) ? files.length : null; | ||||||||||||
| } catch (/** @type {any} */ err) { | ||||||||||||
| // Log at debug level: the count is best-effort and a failure here (e.g. invalid | ||||||||||||
| // pattern syntax, unsupported Node.js version) should not block indexing. | ||||||||||||
| if (typeof core !== "undefined" && typeof core.debug === "function") { | ||||||||||||
| core.debug(`countGlobMatches("${basePath}", "${pattern}") failed: ${err.message}`); | ||||||||||||
| } | ||||||||||||
| return null; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Returns an Octokit client for the given token env var, or the default github client. | ||||||||||||
| * @param {string | undefined} tokenEnvVar | ||||||||||||
|
|
@@ -139,22 +163,36 @@ async function main() { | |||||||||||
| const rawPath = checkout.path; | ||||||||||||
| const resolvedPath = resolveEnvVars(rawPath); | ||||||||||||
| const patterns = checkout.patterns || ["**/*.md"]; | ||||||||||||
|
||||||||||||
| const patterns = checkout.patterns || ["**/*.md"]; | |
| const patterns = | |
| Array.isArray(checkout.patterns) && checkout.patterns.length > 0 | |
| ? checkout.patterns | |
| : ["**/*.md"]; |
Copilot
AI
Mar 24, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When deriving colName for multi-pattern checkouts, the code can silently overwrite an existing entry in collections if another checkout already uses the same name (e.g. a separate checkout named repo-0 collides with repo pattern index 0). Consider detecting collisions before assignment and either failing fast with a clear error or generating a guaranteed-unique name (e.g. include the checkout index in the suffix).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
countGlobMatches()logs "file(s) matched" but the currentglobSync()call will also return directory matches for patterns likedocs/**, so the count can be misleading. Consider callingglobSync(pattern, { cwd: basePath, withFileTypes: true })and counting only entries wheredirent.isFile()(or otherwise filtering out directories) so the logged number reflects files.