-
Notifications
You must be signed in to change notification settings - Fork 379
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
Enhance Handling and Publishing of Invalid Comments in publish_inline_comments
Method
#576
Enhance Handling and Publishing of Invalid Comments in publish_inline_comments
Method
#576
Conversation
… comments As a first option, `publish_code_suggestions` will try to post all review comments in a single GitHub review. This is preferred because it will group all comments together in the GitHub UI under the same review, and will trigger just one notification for any viewers of the PR. If just one of the comments is malformed, the entire API request will fail and none of the comments will be posted to the PR. In the current implementation, the fallback mechanism is to just post each comment separately with `try/except` and skip the invalid comments. This works, but potentially creates a lot of noise in the PR as each comment is posted as in a separate review, creating multiple notifications. This suggested fallback is based on a similar idea, but without creating multiple review notifications. The it works is by iterating over the potential comments, and starting a PENDING review for the current comment. The review is not submitted and does not trigger a notification, but it is verified against the GitHub API, and so we can verify if the comment is valid. After checking all comments we then submit a single review with all the verified comments which is guaranteed to succeed. The end result is having the exact same comments posted to the PR as with the current fallback method, but the downside is having twice as many API calls (for each comment we have 1 extra API call to delete the pending review).
Hey @mrT23, Just had this idea to deal with invalid comments in the What do you think? Does this approach seem reasonable to you? |
Hi @zmeir If this is indeed the case (and you need to be sure about that, because there is no energetic gain in replacing one type of noise with another), than I think it needs some cleaning - defining a function Also, I think its reasonable to add a parameter to enable\disable this semi-fallback mechanism |
p.s. usually there is some problem with the final line number (large PRs). But publishing just the suggestion, on the initial line, would work most of the time |
Yes I tested this on a large PR with many review comments - when you create a PENDING review with the API it's like hitting "Start Review" when using the GitHub UI: When working with the UI you can always add more comments to a PENDING review and then finally submit them all, but unfortunately the GitHub API doesn't offer such option, which is why I only use the PENDING reviews for validity checking. If there was an option to add comments to a PENDING review I would have done it this way, which would have made this fallback option use precisely as many API calls as the current fallback.
Good idea! Added :) I still need to test all the recent changes for correctness so I'm leaving this in Draft. Hopefully I'll be able to get to it later this week. |
@zmeir sure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL
PR Description updated to latest commit (b9951fc) |
@mrT23 - I tested and it seems to work well :) |
PR Analysis
PR Feedback💡 General suggestions: The PR is well-structured and the changes are logically grouped. However, it would be beneficial to include tests for the new functionality to ensure it works as expected and doesn't introduce regressions. Additionally, it would be helpful to include more detailed comments in the code to explain the purpose and functionality of the new methods. 🤖 Code feedback:
✨ Usage guide:Overview:
With a configuration file, use the following template:
See the review usage page for a comprehensive guide on using this tool. |
/improve --extended |
@zmeir let me know when you feel comfortable with the PR, and I will QA it a bit myself to make sure it works as expected |
@mrT23 all ready from my end. Have at it :) |
@zmeir i will make some changes to the PR. i want it to look a bit different, and I think its the faster way. |
verified_comments, invalid_comments = self._verify_inline_comments(comments) | ||
if invalid_comments and get_settings().github.try_fix_invalid_inline_comments: | ||
fixed_comments = self._try_fix_invalid_inline_comments([comment for comment, _ in invalid_comments]) | ||
verified_fixed_comments, invalid_fixed_comments = self._verify_inline_comments(fixed_comments) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is wrong from my tests. it consistently failed on valid (one-line) code messages.
i don't think the logic works for these kind of messages.
this is also extra calls. again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A one-line comment isn't necessarily valid, it may be outside the valid range of the hunk (or otherwise invalid). Did your test comment pass when calling self.pr.create_review
directly?
In my tests whenever I had a comment deemed invalid I then tried to post it directly with self.pr.create_review
to make sure it indeed failed and it wasn't a false-positive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It deleted for me all valid one-line comments. see my example below. have you ever succeded in publishing any one-line comment ?
and in addition, its extra calls. again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About the extra API call: That's true, a fixed message incurs an extra call to the GitHub API, but that makes sense - you create a new message so you have to verify that one as well. It's unfair to compare it to the number of API calls before this PR because there was previously no attempt to fix the invalid message at all - it was just discarded. Also, this is why this feature is behind a separate configuration toggle so you can choose to disable it irrespectively of the primarily feature of this PR (the review comment verification)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @zmeir the revised PR is In a branch: p.s. (2) i can guess it has some connections to the rate limits. so this fallback mechanism has strong advantages, but it also has downsides. (3) |
publish_code_suggestions
in case of invalid commentspublish_code_suggestions
Function
PR Description updated to latest commit (b9951fc) |
publish_code_suggestions
Functionpublish_inline_comments
Method
PR Description updated to latest commit (b9951fc) |
merged in #594 |
User description
As a first option,
publish_code_suggestions
will try to post all review comments in a single GitHub review. This is preferred because it will group all comments together in the GitHub UI under the same review, and will trigger just one notification for any viewers of the PR.If just one of the comments is malformed, the entire API request will fail and none of the comments will be posted to the PR. In the current implementation, the fallback mechanism is to just post each comment separately with
try/except
and skip the invalid comments. This works, but potentially creates a lot of noise in the PR as each comment is posted as in a separate review, creating multiple notifications.This suggested fallback is based on a similar idea, but without creating multiple review notifications. The way it works is by iterating over the potential comments, and starting a PENDING review for the current comment. The review is not submitted and does not trigger a notification, but it is verified against the GitHub API, and so we can verify if the comment is valid. After checking all comments we then submit a single review with all the verified comments which is guaranteed to succeed.
The end result is having the exact same comments posted to the PR as with the current fallback method, but the downside is having twice as many API calls (for each comment we have 1 extra API call to delete the pending review).
In addition, this PR also adds an option to try and fix invalid comments by removing the suggestion part and posting it just on the first line.
Type
Enhancement
Description
This PR introduces an enhancement to the
publish_inline_comments
method in thegithub_provider.py
file. The main changes include:configuration.toml
file:publish_inline_comments_fallback_with_verification
andtry_fix_invalid_inline_comments
. These options control the new fallback mechanism and the attempt to fix invalid comments, respectively.Changes walkthrough
github_provider.py
pr_agent/git_providers/github_provider.py
The
publish_inline_comments
method has been enhanced tohandle invalid comments more gracefully. It now verifies
each comment against the GitHub API and discards invalid
ones before publishing. It also attempts to fix invalid
comments by removing the suggestion part and posting the
comment just on the first line. The fallback mechanism for
publishing comments has been improved to reduce the number
of notifications triggered.
configuration.toml
pr_agent/settings/configuration.toml
Two new configuration options have been added:
publish_inline_comments_fallback_with_verification
andtry_fix_invalid_inline_comments
. These options control thenew fallback mechanism for publishing comments and the
attempt to fix invalid comments, respectively.
✨ Usage guide:
Overview:
The
describe
tool scans the PR code changes, and generates a description for the PR - title, type, summary, walkthrough and labels. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.When commenting, to edit configurations related to the describe tool (
pr_description
section), use the following template:With a configuration file, use the following template:
Enabling\disabling automation
meaning the
describe
tool will run automatically on every PR, will keep the original title, and will add the original user description above the generated description.the tool will replace every marker of the form
pr_agent:marker_name
in the PR description with the relevant content, wheremarker_name
is one of the following:type
: the PR type.summary
: the PR summary.walkthrough
: the PR walkthrough.Note that when markers are enabled, if the original PR description does not contain any markers, the tool will not alter the description at all.
Custom labels
The default labels of the
describe
tool are quite generic: [Bug fix
,Tests
,Enhancement
,Documentation
,Other
].If you specify custom labels in the repo's labels page or via configuration file, you can get tailored labels for your use cases.
Examples for custom labels:
Main topic:performance
- pr_agent:The main topic of this PR is performanceNew endpoint
- pr_agent:A new endpoint was added in this PRSQL query
- pr_agent:A new SQL query was added in this PRDockerfile changes
- pr_agent:The PR contains changes in the DockerfileThe list above is eclectic, and aims to give an idea of different possibilities. Define custom labels that are relevant for your repo and use cases.
Note that Labels are not mutually exclusive, so you can add multiple label categories.
Make sure to provide proper title, and a detailed and well-phrased description for each label, so the tool will know when to suggest it.
Utilizing extra instructions
The
describe
tool can be configured with extra instructions, to guide the model to a feedback tailored to the needs of your project.Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Notice that the general structure of the description is fixed, and cannot be changed. Extra instructions can change the content or style of each sub-section of the PR description.
Examples for extra instructions:
Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.
More PR-Agent commands
See the describe usage page for a comprehensive guide on using this tool.