coderabbitai / ai-pr-reviewer

AI-based Pull Request Summarizer and Reviewer with Chat Capabilities.
https://coderabbit.ai
MIT License
1.51k stars 287 forks source link

Fix tokens calculation & cleanup the file summary prompt logic #426

Closed HyunggyuJang closed 1 year ago

HyunggyuJang commented 1 year ago

Previously, the tokens calculation was incorrect. With this PR, now it is correctly calculated & reuse the instantiated prompt for readability and efficiency.

Summary by CodeRabbit

**Bug fix:**
- Fixed the incorrect calculation of `tokens` in `src/review.ts`.
- Improved code readability and efficiency by reusing instantiated prompt.
- Removed diff tokens check, now only checking if token count exceeds limit.
- Files exceeding token limit are now skipped and logged in `summariesFailed`.

> 🎉 Code's been tweaked, bugs have been fixed, 🐛
> Efficiency improved, with no tricks. 🎩✨
> Tokens counted right, no more plight, 🧮
> Celebrate this PR, it's quite a sight! 🥳🎊
github-actions[bot] commented 1 year ago

Image description CodeRabbit

Walkthrough:

This PR primarily addresses the issue of incorrect token calculation in the review process. It enhances code readability and efficiency by reusing instantiated prompts and simplifying token count checks. Files exceeding the token limit are now appropriately handled.

Changes:

File Summary
src/review.ts The token calculation has been corrected for accuracy. An instantiated prompt is now reused to improve code readability and efficiency. The check for tokens has been simplified, only verifying if the token count exceeds the limit. Files that exceed the token limit are skipped and added to the summariesFailed array.