Skip to content

Convert repo IO and processing to async/await#260

Merged
begin-again merged 4 commits into
masterfrom
ba/grefp-refactor
May 29, 2026
Merged

Convert repo IO and processing to async/await#260
begin-again merged 4 commits into
masterfrom
ba/grefp-refactor

Conversation

@begin-again

@begin-again begin-again commented May 29, 2026

Copy link
Copy Markdown
Owner

Replace blocking fs/path calls with node:fs/promises and node:path and convert package retrieval, repo discovery, and git reflog processing to async/await to avoid synchronous I/O and improve robustness and error propagation.

Improve error construction to preserve the original error as the cause. Refactor git output parsing to filter earlier and collect per-repo errors without failing the whole run. Update tests to use async patterns and the platform path separator.

Changed files:

  • src/common/repos.js
  • src/grefplus/cmdline.js
  • src/grefplus/index.js
  • test/repos.spec.js

Summary by CodeRabbit

  • Refactor

    • Migrated internal filesystem operations to asynchronous APIs for improved responsiveness and performance.
    • Modernized codebase to use async/await patterns throughout processing logic.
    • Updated Node.js module imports to use standardized prefixes.
  • Bug Fixes

    • Enhanced error handling to provide better diagnostic information in exception contexts.

Review Change Stack

Replace blocking fs/path calls with node:fs/promises and node:path and
convert package retrieval, repo discovery, and git reflog processing to
async/await to avoid synchronous I/O and improve robustness and error
propagation.

Improve error construction to preserve the original error as the cause.
Refactor git output parsing to filter earlier and collect per-repo errors
without failing the whole run. Update tests to use async patterns and the
platform path separator.

Changed files:
- src/common/repos.js
- src/grefplus/cmdline.js
- src/grefplus/index.js
- test/repos.spec.js
@begin-again begin-again self-assigned this May 29, 2026
@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@begin-again, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 9 minutes and 56 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5371da7e-25bc-42ff-9a41-7dadb3fa0f57

📥 Commits

Reviewing files that changed from the base of the PR and between 406d93a and 428ad7b.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (9)
  • package.json
  • src/common/engine.js
  • src/grefplus/index.js
  • src/spawner/index.js
  • src/yarn/index.js
  • test/engine.spec.js
  • test/git-seq.spec.js
  • test/git.spec.js
  • test/temp.spec.js
📝 Walkthrough

Walkthrough

This PR converts filesystem access from synchronous Node fs APIs to promise-based fs/promises, making getPackage and allRepoPaths async. All dependent code in grefplus services is refactored to async/await, with the entrypoint orchestrating parallel repo processing. Tests are updated to await the async functions.

Changes

Async/await migration for repository and package utilities

Layer / File(s) Summary
Async filesystem API migration in repos.js
src/common/repos.js
getPackage and allRepoPaths are converted to async functions using fs/promises with readFile and readdir. Module imports switch to node:-prefixed fs/promises and path. Error fallback semantics remain unchanged.
Async adoption in grefplus services
src/grefplus/index.js
Built-in imports updated to node:-prefixed. processRepo becomes async, parsing git reflog output segment-by-segment and filtering by date. The main entrypoint is rewritten as async, awaiting allRepoPaths, orchestrating parallel processRepo execution, sorting results, and handling errors via logErrors.
Test suite updates for async behavior
test/repos.spec.js
Test cases for allRepoPaths and getPackage converted to async functions with awaited calls. Module imports updated to node:-prefixed path. Assertion expectations for results and error handling remain the same.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 From sync to async, what a delight,
No more blocking calls in the night,
Promises and awaits flow so clean,
The finest refactoring I've seen! 🌙✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Convert repo IO and processing to async/await' accurately and concisely describes the main change across all modified files—migrating synchronous filesystem APIs to promise-based equivalents and converting processing logic to async/await patterns.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ba/grefp-refactor

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/grefplus/index.js`:
- Around line 60-79: The code collapses repo to basename(repo) and loses root
context; change the repo identifier used in lines.push and errors.push to
preserve full or root-relative path (e.g., stop using repoName from
basename(repo) and instead use repo or path.relative(root, repo) so duplicate
basenames remain distinguishable), update the occurrences where repoName is
assigned and where errors.push({ repo: basename(repo) ... }) to use the chosen
full/relative path, and ensure any logging or downstream consumers that expect
repoName are updated accordingly.
- Around line 120-123: The current code maps over repos to start one process per
repo and awaits Promise.all(promises), which can spawn unbounded git processes;
change this to a bounded concurrency approach by introducing a concurrency limit
(e.g., const CONCURRENCY = N) and use a worker/pool or a small promise-limiter
to only run up to CONCURRENCY concurrent calls to processRepo; specifically,
replace the direct repos.map(...) usage with a limited runner that enqueues
processRepo(repo, errors) tasks and schedules them with at most CONCURRENCY
active tasks (or use a lightweight helper like p-limit to wrap processRepo),
then await Promise.all on the array of limited promises so no more than the
configured number of git log processes run at once.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b5d2f8d0-01cd-494f-956f-059cca56c9bc

📥 Commits

Reviewing files that changed from the base of the PR and between 42e2d25 and 406d93a.

📒 Files selected for processing (4)
  • src/common/repos.js
  • src/grefplus/cmdline.js
  • src/grefplus/index.js
  • test/repos.spec.js

Comment thread src/grefplus/index.js Outdated
Comment thread src/grefplus/index.js Outdated
Convert CLI yargs checks to await the asynchronous version validator
so repository engine checks can perform async I/O.

Update unit tests to use async/await and adjust stubs to return/resolves values; add tests covering oldest/max/min selection logic.

Remove slow/flaky git integration tests.

Update the temp test to use a real temp base.

Also bump dependency versions for simple-git and uuid.

Changed files:
- package.json
- src/spawner/index.js
- src/yarn/index.js
- test/engine.spec.js
- test/temp.spec.js
- test/git-seq.spec.js (deleted)
- test/git.spec.js (deleted)
Comment thread test/temp.spec.js Fixed
Comment thread test/temp.spec.js Fixed
Throttle repo processing by batching repos into concurrent
chunks of 8 to avoid spawning too many parallel tasks and to
reduce resource contention.

Strengthen error reporting by narrowing the errors param to an
array of {repo, error} and by recording the full repo path rather
than the basename when pushing errors.

Update tests to import node:fs and node:path and fix a typo in a
test description; minor cleanup of temp init/destroy calls.

Changed files:
- src/grefplus/index.js
- test/temp.spec.js
@sonarqubecloud

Copy link
Copy Markdown

@begin-again begin-again merged commit faf68f4 into master May 29, 2026
8 checks passed
@begin-again begin-again deleted the ba/grefp-refactor branch May 29, 2026 13:44
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.

2 participants