feat: Add automatic PR summary generator #19
Reference in New Issue
Block a user
Delete Branch "feature/pr-summary-generator"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements automatic PR summary generation feature that analyzes pull
request diffs and generates comprehensive summaries.
Features:
Implementation:
Usage:
Related: Issue #2 - Milestone 2 feature delivery
📋 Pull Request Summary
This PR introduces an automated PR summary generation feature that creates comprehensive, structured summaries for pull requests, especially when descriptions are missing. It supports both automatic generation on PR open events and manual triggering via the
@codebot summarizecommand in PR comments.Type: ✨ Feature
Changes
✅ Added:
pr_summary.mdfor instructing the LLM on summary generationconfig.yml📝 Modified:
@codebot summarizecommand and auto-generate summaries for empty PR descriptionsFiles Affected
tools/ai-review/agents/pr_agent.py- Added PR summary generation methods, command handling for@codebot summarize, and auto-summary on PR open with empty descriptionstools/ai-review/prompts/pr_summary.md- New prompt template defining the structure and requirements for generating PR summaries using the LLMtools/ai-review/config.yml- Added configuration options to enable/disable auto-summary and control posting behaviorREADME.md- Updated documentation to include the PR summary feature and the@codebot summarizecommandCLAUDE.md- Extended internal documentation with detailed explanation of the PR summary feature, implementation details, and usage scenariostests/test_ai_review.py- Added comprehensive tests for PR summary prompt existence, formatting, command handling, and configuration validationImpact
🟡 Scope: Medium
Introduces a new automated feature that improves PR documentation and review efficiency without altering existing review logic. It enhances developer experience by providing standardized summaries and supports manual and automatic invocation with minimal risk.
AI Code Review - Inline Comments
[LOW] Testing
The tests cover prompt existence, formatting, command handling, and configuration, but do not include tests for failure modes such as LLM errors or empty diffs during summary generation.
Recommendation: Add tests simulating LLM failures, empty diffs, and API errors to ensure robust error handling and fallback behavior.
[LOW] Architecture
The method _generate_pr_summary attempts to update the PR description via the Gitea API, but the comment notes that this may not be supported and falls back to posting a comment. This fallback logic is appropriate but could be clarified or improved by explicitly checking API capabilities or documenting limitations.
Recommendation: Consider adding a capability check or configuration option to explicitly control whether to attempt PR description updates, and document the Gitea API limitations regarding PR description updates.
[LOW] Maintainability
The execute() method handles multiple commands (summarize, review-again) in a single conditional block, which could grow as more commands are added.
Recommendation: Refactor command handling into a dispatch method or dictionary mapping commands to handlers to improve scalability and readability.
[LOW] Readability
The can_handle() method checks for both 'review-again' and 'summarize' commands in a single return statement, which slightly reduces clarity.
Recommendation: Separate the checks for each command into distinct variables or conditions with comments to improve readability.
[LOW] Performance
The _generate_pr_summary method loads the entire PR diff and sends it to the LLM in one prompt. For very large diffs, this could lead to performance or token limit issues.
Recommendation: Consider adding diff size checks or truncation strategies before sending to the LLM, or implement incremental summarization for very large PRs.
[LOW] Maintainability
The prompt template uses double curly braces for JSON placeholders, which requires careful escaping to avoid formatting errors.
Recommendation: Ensure prompt template placeholders are properly escaped and tested to prevent KeyError during formatting, as verified in tests.
AI Code Review
This PR introduces an automated PR summary generation feature integrated into the existing PRAgent. It supports auto-generation of summaries for PRs with empty descriptions and manual triggering via the
@codebot summarizecommand in PR comments. The feature uses a new prompt template to instruct the LLM to produce structured JSON summaries, which are then formatted and posted as comments or optionally update the PR description. Comprehensive tests validate prompt presence, formatting, command handling, and configuration.Summary
Review Findings
tools/ai-review/agents/pr_agent.py:147- The method _generate_pr_summary attempts to update the PR description via the Gitea API, but the comment notes that this may not be supported and falls back to posting a comment. This fallback logic is appropriate but could be clarified or improved by explicitly checking API capabilities or documenting limitations.tools/ai-review/agents/pr_agent.py:123- The execute() method handles multiple commands (summarize, review-again) in a single conditional block, which could grow as more commands are added.tools/ai-review/agents/pr_agent.py:92- The can_handle() method checks for both 'review-again' and 'summarize' commands in a single return statement, which slightly reduces clarity.tools/ai-review/agents/pr_agent.py:150- The _generate_pr_summary method loads the entire PR diff and sends it to the LLM in one prompt. For very large diffs, this could lead to performance or token limit issues.tools/ai-review/prompts/pr_summary.md:1- The prompt template uses double curly braces for JSON placeholders, which requires careful escaping to avoid formatting errors.tests/test_ai_review.py:600- The tests cover prompt existence, formatting, command handling, and configuration, but do not include tests for failure modes such as LLM errors or empty diffs during summary generation.Overall Severity:
LOWAI Recommendation: Approve
@None
Summary:
Please provide the title and body of the issue you would like summarized.
@None
Summary:
Please provide the title and body of the issue you would like summarized.
Pull request closed