Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced PR review system to focus on critical comments only #10

Merged
merged 2 commits into from
Nov 18, 2024
Merged

Conversation

bstanga
Copy link
Contributor

@bstanga bstanga commented Nov 18, 2024

No description provided.

Copy link

github-actions bot commented Nov 18, 2024

📖 Walkthrough

Enhanced the PR review system to prioritize critical comments and provide a more structured review summary. Added functionality to filter out non-critical comments and generate a detailed review summary that includes commit history, processed files, and categorized comments (actionable vs skipped).

Changes

File Summary
src/diff.ts Changed the output text from __comment_chain__ to __existing_comment_thread__ for better clarity in representing existing comment threads.
src/messages.ts Implemented buildReviewSummary function that generates a structured review message with sections for commits, processed files, actionable comments, and skipped comments. Added visual indicators (✅ LGTM or 🚨 needs attention) based on comment status.
src/prompts.ts Added critical boolean field to AIComment type to identify important comments. Updated system prompt to exclude style/formatting comments and improved instructions for comment generation. Enhanced comment validation schema.
src/pull_request.ts Modified review submission to filter comments based on criticality, only submitting critical comments and typos. Integrated new review summary builder to provide comprehensive review feedback with categorized comments.

autogenerated by presubmit.ai

@github-actions github-actions bot changed the title only submit critical comments @presubmitai Enhanced PR review system to focus on critical comments only Nov 18, 2024
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Review complete

Comment on lines 253 to 258
if (!!comment.end_line && (comment.critical || comment.label === "typo")) {
lineComments.push(comment);
} else {
skippedComments.push(comment);
}
}

Choose a reason for hiding this comment

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

The condition !!comment.end_line is redundant since end_line is already required in the schema. Additionally, the filtering logic for critical comments should be more explicit. Consider:

if (comment.critical || comment.label === 'typo') {
  lineComments.push(comment);
} else {
  skippedComments.push(comment);
}

src/messages.ts Outdated
Comment on lines 125 to 128
if (actionableComments.length == 0) {
body += `✅ **LGTM!**\n\n`;
} else {
body += `🚨 **Pull request needs attention.**\n\n`;

Choose a reason for hiding this comment

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

The condition uses == instead of === for strict equality comparison. While this might work, it's better to use strict equality in TypeScript/JavaScript to prevent potential type coercion issues:

if (actionableComments.length === 0) {

Copy link
Contributor Author

@bstanga bstanga left a comment

Choose a reason for hiding this comment

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

LGTM!

Review Summary

Commits Considered (1)
  • 317edc3: only submit critical comments
Files Processed (4)
  • src/diff.ts (1 hunk)
  • src/messages.ts (2 hunks)
  • src/prompts.ts (5 hunks)
  • src/pull_request.ts (5 hunks)
Actionable Comments (0)
Skipped Comments (3)
  • src/messages.ts [125-125]

    readability: "Variable name could be more descriptive"

  • src/pull_request.ts [253-254]

    enhancement: "Redundant condition check"

  • src/messages.ts [169-170]

    maintainability: "Duplicate section header in code"

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Review complete

Comment on lines +253 to +258
if (comment.critical || comment.label === "typo") {
lineComments.push(comment);
} else {
skippedComments.push(comment);
}
}

Choose a reason for hiding this comment

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

The filtering criteria for comments (critical or typo) is currently hardcoded. Consider making this configurable through a settings file or environment variables to allow users to customize which types of comments they want to see as actionable vs skipped. This would provide more flexibility for different teams' needs.

Comment on lines +125 to +129
if (actionableComments.length === 0) {
body += `✅ **LGTM!**\n\n`;
} else {
body += `🚨 **Pull request needs attention.**\n\n`;
}

Choose a reason for hiding this comment

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

The status message could be more informative by including the count of actionable comments when attention is needed. Consider modifying the message to something like: 🚨 **Pull request needs attention (X actionable comments)**. This gives reviewers an immediate sense of the review's scope.

Comment on lines +148 to +156
let fileText = `- ${diff.filename}`;
if (diff.status === "renamed") {
fileText += ` (from ${diff.previous_filename})`;
}
fileText += ` _(${diff.hunks.length} ${
diff.hunks.length === 1 ? "hunk" : "hunks"
})_`;
body += `${fileText}\n`;
}

Choose a reason for hiding this comment

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

Consider adding an indicator for the type of change (added/modified/deleted) for each file in the summary. While the code handles renamed files, it would be helpful to show the change type for other files as well. This information helps reviewers quickly understand the scope of changes in each file.

Comment on lines 260 to 261
// Try to submit all comments at once
try {

Choose a reason for hiding this comment

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

Consider adding a check for empty lineComments array before attempting to submit the review. While this might not cause an error, it's a good practice to handle edge cases explicitly. You could either skip the submission or log a debug message in such cases.

Copy link
Contributor Author

@bstanga bstanga left a comment

Choose a reason for hiding this comment

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

LGTM!

Review Summary

Commits Considered (1)
Files Processed (2)
  • src/messages.ts (2 hunks)
  • src/pull_request.ts (5 hunks)
Actionable Comments (0)
Skipped Comments (3)
  • src/messages.ts [125-129]

    enhancement: "Status message could be more informative by including issue count"

  • src/pull_request.ts [253-258]

    maintainability: "Extract comment filtering logic into a dedicated function"

  • src/pull_request.ts [260-261]

    best practice: "Add validation for empty comments before review submission"

@bstanga bstanga merged commit d9f2bd0 into main Nov 18, 2024
1 check passed
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.

1 participant