Skip to content

Conversation

simonstamm
Copy link
Contributor

@simonstamm simonstamm commented May 8, 2025

User description

It currently isn't retriggering when the MR goes from draft to ready. The main issue is in the is_draft_ready function which doesn't correctly handle the webhook data format coming from GitLab:

{
  "changes": {
    "draft": {
      "previous": true,
      "current": false
    },
  },
}

The problem is that the function is comparing string values 'true' and 'false', but in the webhook data, the values are booleans. In my PR, it converts string values to boolean if needed for compatibility with different GitLab versions and uses strict type comparison (is True and is False) to ensure correct behavior.


PR Type

Bug fix


Description

  • Fixes detection of draft-to-ready state in GitLab MRs

  • Adds compatibility for both boolean and string webhook values

  • Ensures strict type comparison for draft status changes


Changes walkthrough 📝

Relevant files
Bug fix
gitlab_webhook.py
Improve MR draft-to-ready detection for GitLab webhooks   

pr_agent/servers/gitlab_webhook.py

  • Updates is_draft_ready to handle both boolean and string values
  • Converts string values to booleans for compatibility
  • Uses strict type comparison for draft status detection
  • +12/-2   

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The function now handles type conversion but doesn't have error handling for potential type conversion issues. If the string values aren't 'true' or 'false' but some other text, the conversion logic might not work as expected.

    if isinstance(previous, str):
        previous = previous.lower() == 'true'
    if isinstance(current, str):
        current = current.lower() == 'true'

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Handle all truthy values

    The current implementation only handles 'true' string value but GitLab may use
    different string representations for boolean values. Consider handling all
    possible string representations by checking if the lowercase string is in a set
    of truthy values.

    pr_agent/servers/gitlab_webhook.py [93-97]

     # Convert to boolean if they're strings
     if isinstance(previous, str):
    -    previous = previous.lower() == 'true'
    +    previous = previous.lower() in ('true', 'yes', '1', 'on')
     if isinstance(current, str):
    -    current = current.lower() == 'true'
    +    current = current.lower() in ('true', 'yes', '1', 'on')
    • Apply / Chat
    Suggestion importance[1-10]: 6

    __

    Why: The suggestion improves robustness by handling multiple string representations of boolean values beyond just 'true', which is a good practice for API integrations. While the current implementation works for GitLab's standard format, the enhancement provides better compatibility with potential variations.

    Low
    • More
    • Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.

    @mrT23
    Copy link
    Collaborator

    mrT23 commented May 8, 2025

    Thanks for the fix @simonstamm

    Gitlab has a lot of versions, and they seem to make an effort to change the webhook data between one version to another ...

    @mrT23 mrT23 merged commit 36307e6 into qodo-ai:main May 8, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants