-
Notifications
You must be signed in to change notification settings - Fork 739
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 gitlab webhook handling for push events without object_attributes #1555
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Push events don't have Fortunately, for existing MRs, a push event will result in an update in the MR (push operations without an MR won't have a merge request event). Thus, we can determine if it's a merge request triggered by a push by checking if it includes This way, the logic related to push events can be removed. |
await _perform_commands_gitlab("pr_commands", PRAgent(), url, log_context, data) | ||
|
||
# for push event triggered merge requests | ||
elif data['object_attributes'].get('action') == 'update' and data['object_attributes'].get('oldrev'): |
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.
@GOOD21
This is definitely simpler (and less API calls) than using 'get_mr_url_from_commit_sha'.
However, I am wondering if it is reliable, and if its specific only for push events.
Do you think that this 'oldrev' object will appear for all versions of gitlab ? do you have some documentation about it ?
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.
cc
@ofir-frd
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.
@GOOD21 This is definitely simpler (and less API calls) than using 'get_mr_url_from_commit_sha'. However, I am wondering if it is reliable, and if its specific only for push events.
Do you think that this 'oldrev' object will appear for all versions of gitlab ? do you have some documentation about it ?
@mrT23 Yes, I checked the official GitLab documentation, and this field is present in at least versions 15, 16, and 17. It only has a value when there are actual code changes.
The field
object_attributes.oldrev
is only available when there are actual code changes, like:
- New code is pushed.
- A suggestion is applied.
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.
LGTM
User description
fix push events don't automatically trigger pr_commands due to missing object_attributes
Push events don't have
object_attributes
, so it's impossible to filter based on the title or other information, meaning push operations shouldn't involve any execution logic checks.Fortunately, for existing MRs, a push event will result in an update in the MR (push operations without an MR won't have a merge request event). Thus, we can determine if it's a merge request triggered by a push by checking if it includes
object_attributes.oldrev
.This way, the logic related to push events can be removed.
PR Type
Bug fix, Enhancement
Description
Fixed handling of push events without
object_attributes
.Enhanced logging for better debugging and event processing.
Improved conditional checks for event types and commands.
Changes walkthrough 📝
gitlab_webhook.py
Improved event handling and logging in webhook
pr_agent/servers/gitlab_webhook.py
object_attributes
in event data.push
andnote
event types.push_commands
andpr_commands
.