feat: Add automatic PR summary generator #20
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 creation and manual triggering via the
@codebot summarizecommand, enhancing review efficiency and standardization.Type: ✨ Feature
Changes
✅ Added:
pr_summary.mdfor structured summary generationconfig.yml@codebot summarizecommand in PR comments📝 Modified:
Files Affected
tools/ai-review/agents/pr_agent.py- Added PR summary generation methods, command handling for summarize, and auto-summary on PR open with empty descriptiontools/ai-review/prompts/pr_summary.md- New prompt template defining the structure and requirements for PR summary generationtools/ai-review/config.yml- Added configuration for enabling/disabling auto-summary and choosing comment vs description postingREADME.md- Updated documentation to include PR summary feature and@codebot summarizecommand usageCLAUDE.md- Expanded developer workflow documentation with detailed explanation of PR summary generation feature and commandstests/test_ai_review.py- Added comprehensive tests covering prompt existence, formatting, command handling, summary formatting, and config validation for PR summariesImpact
🟡 Scope: Medium
Introduces a new automated feature that improves PR documentation and review workflows without altering existing review logic. It adds new commands and configuration but maintains backward compatibility and does not affect core functionality.
AI Code Review - Inline Comments
[LOW] Maintainability
The _generate_pr_summary method continues with the regular PR review after posting the summary for empty PR descriptions, but it does not explicitly handle the case where summary generation fails. This could lead to silent failures without clear feedback.
Recommendation: Add explicit logging or error handling to notify if summary generation fails during auto-summary on PR open, to improve observability.
[LOW] Readability
The _format_pr_summary method uses hardcoded emoji mappings and string literals for formatting the summary. While functional, this could be extracted to constants or configuration for easier updates and localization.
Recommendation: Extract emoji mappings and repeated strings into class-level constants or configuration to improve maintainability and facilitate future changes.
[LOW] Architecture
The method _generate_pr_summary mixes concerns of generating the summary, formatting it, and posting it to Gitea. This tight coupling could make testing and future extensions harder.
Recommendation: Separate concerns by splitting summary generation, formatting, and posting into distinct methods or services to improve modularity and testability.
[LOW] Correctness
The fallback logic when updating the PR description fails is to post the summary as a comment. However, the comment is posted without indicating it is a fallback, which might confuse users.
Recommendation: Include a note in the fallback comment indicating that updating the PR description failed and the summary is posted as a comment instead.
[LOW] Testing
The tests cover prompt existence, formatting, command handling, and summary formatting well. However, there is no test verifying the behavior when the LLM returns malformed or incomplete JSON data.
Recommendation: Add tests simulating malformed or incomplete LLM responses to ensure the agent handles such cases gracefully without crashing or posting invalid summaries.
[LOW] Readability
The can_handle method checks for both 'review-again' and 'summarize' commands in a single conditional, which slightly reduces clarity.
Recommendation: Separate the checks for 'review-again' and 'summarize' commands into distinct conditionals or helper methods to improve readability and future extensibility.
AI Code Review
This PR introduces an automated PR summary generation feature within the PRAgent, enabling automatic and manual generation of structured, informative summaries for pull requests. It includes a new prompt template, configuration options, and command handling for '@codebot summarize'. Comprehensive tests cover prompt existence, formatting, command handling, and configuration validation.
Summary
Review Findings
tools/ai-review/agents/pr_agent.py:130- 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 (@codebot summarize and review-again) in a single conditional block, which could grow as more commands are added.tools/ai-review/agents/pr_agent.py:140- The _generate_pr_summary method loads the entire PR diff and sends it to the LLM for analysis. For very large diffs, this could be inefficient or exceed LLM input limits.tools/ai-review/prompts/pr_summary.md:1- The prompt template is well-structured and clear, but the JSON output example uses double curly braces '{{' and '}}' which may confuse some users or tools that do not expect escaped braces.tests/test_ai_review.py:600- The tests for PR summary generation cover prompt existence, formatting, command handling, and config validation but do not include tests for failure scenarios such as LLM call failures or empty diffs.Overall Severity:
LOWAI Recommendation: Approve
📋 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 on 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 descriptiontools/ai-review/prompts/pr_summary.md- New prompt template defining the structure and requirements for PR summary generation by the LLMtools/ai-review/config.yml- Added configuration for enabling/disabling auto-summary and choosing whether to post as comment or update PR descriptionREADME.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, its workflow, configuration, and usagetests/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 reviewer experience without altering existing review functionality. The feature is opt-in and configurable, minimizing risk while enhancing usability.
AI Code Review - Inline Comments
[LOW] Testing
The tests for PR summary generation cover prompt existence, formatting, command handling, and config validation but do not include tests for failure scenarios such as LLM call failures or empty diffs.
Recommendation: Add tests simulating LLM failures, empty diffs, and API errors to ensure robust error handling and user feedback.
[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 a dedicated method to update PR descriptions if supported by the API, or document this limitation clearly in the code and user documentation.
[LOW] Maintainability
The execute method handles multiple commands (@codebot summarize and 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] Performance
The _generate_pr_summary method loads the entire PR diff and sends it to the LLM for analysis. For very large diffs, this could be inefficient or exceed LLM input limits.
Recommendation: Implement diff size checks and consider summarizing or chunking large diffs before sending to the LLM to avoid performance degradation or failures.
[LOW] Readability
The prompt template is well-structured and clear, but the JSON output example uses double curly braces '{{' and '}}' which may confuse some users or tools that do not expect escaped braces.
Recommendation: Add a comment or note in the prompt explaining the use of double curly braces for escaping in the template to avoid confusion.
@None
Summary:
Please provide the issue title and body you would like summarized.