Add reusable model-backed code review tool#4
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughThis PR introduces a complete reusable code-review tool with a core library ( ChangesCode Review Tool
🎯 4 (Complex) | ⏱️ ~60 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 7
🤖 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 `@bin/review-code.mjs`:
- Around line 166-168: The resultPath function only checks for POSIX-style
absolute paths with startsWith('/') which breaks on Windows; update resultPath
(function name) to use Node's path module (imported from 'node:path') and
replace the manual startsWith/replace logic with path.isAbsolute to detect
absolute stateDir and path.join (or path.resolve) to construct the final path so
both POSIX and Windows absolute/relative --state-dir values are handled
correctly.
In `@lib/code-review.mjs`:
- Around line 814-816: The timestampId function contains a no-op
.replace('T','T'); remove that redundant replace call from timestampId (or if
the intent was to substitute the 'T' with another character such as a space or
underscore, change the second argument accordingly) so the function returns the
intended ISO-based id without an unnecessary no-op; update the implementation in
the timestampId function accordingly.
- Around line 403-426: The fetch call that posts to
`${baseUrl}/chat/completions` can hang because it has no timeout; wrap the
request with an AbortController: create an AbortController, pass its signal into
the existing fetch call, start a setTimeout (e.g., 30s or configurable) that
calls controller.abort(), and clear that timeout once a response is received;
ensure the abort is caught and rethrown as a CodeReviewError (or mapped to the
existing error-handling path) so callers get a clear timeout message. Reference
the existing fetch invocation (variable res) and the CodeReviewError thrown on
non-ok responses when adding the AbortController/signal and timeout logic.
In `@test/code-review.test.mjs`:
- Around line 42-101: The test "review run persists findings, preserves triage,
and reports status" creates a temporary repo via createRepo() but never removes
it; update the test to clean up the temp repo (use fs.rmSync or fs.promises.rm)
in a finally block around the async test body or register cleanup with the Node
test runner (e.g., test.afterEach/test.teardown) so the directory created by
createRepo() is removed after the test; modify the test function (the test(...)
block) to capture the repo variable and ensure deletion even on failure.
- Line 167: The test uses import.meta.dirname (seen in the cwd:
path.resolve(import.meta.dirname, '..') call) which requires Node >=20.11.0;
either update package.json engines to "node": ">=20.11.0" to guarantee
compatibility, or refactor the test to avoid import.meta.dirname by deriving the
directory from import.meta.url (use fileURLToPath(import.meta.url) and
path.dirname) and then pass that into path.resolve — update the code referencing
import.meta.dirname accordingly.
- Around line 18-40: The test leaves temporary resources around: clean up the
external temp file and the repo directory created by createRepo() by wrapping
the setup in a try/finally (or using after/teardown) and in the finally call
fs.unlinkSync(outside) if the outside file exists and remove the repo directory
recursively (e.g., fs.rmSync(repo, { recursive: true, force: true }) or a
project teardown helper); ensure these cleanup calls run even if assertions fail
so mapReviewFeatures and the assertions around feature (feature_id 'app') still
execute but resources are always removed afterwards.
- Around line 183-214: createRepo currently creates temp repos but never removes
them; change createRepo to return an object like { repo, cleanup } where cleanup
is a function that removes the temp directory (e.g., using fs.rmSync(repo, {
recursive: true, force: true }) or equivalent), and update tests that call
createRepo to destructure the returned cleanup and call it in a finally block
(or afterEach) to ensure temp directories are removed; reference the createRepo
function and tests that call it when making the changes.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: c63a1221-b11f-47b4-8685-cfeb81f6354e
⛔ Files ignored due to path filters (2)
README.mdis excluded by!*.mdpackage-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (7)
.github/workflows/ci.yml.gitignorebin/review-code.mjseslint.config.jslib/code-review.mjspackage.jsontest/code-review.test.mjs
Summary
Validation
Notes
Summary by CodeRabbit
New Features
review-codecommand supporting code review initialization, feature mapping, automated review execution, status tracking, and report generation.Chores
Tests