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

Fixes HTML base url logic #1591

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fixes HTML base url logic #1591

wants to merge 1 commit into from

Conversation

bbartels
Copy link

@bbartels bbartels commented Feb 28, 2025

PR Type

Bug fix

I am unsure as to what the logic beforehand was trying to accomplish. When would api/ ever be present in the base_url? Not sure if this was a typo of some sort. I've modified the logic to just strip api from the baseurl.
This fixes the situation we are encountering with a base_url of: https://api.git.local resulting in a html url of https://github.com

This logic will handle any case:

https://api.git.local -> https://git.local
https://api.git.local/api/v3 -> https://git.local

Description

  • Fixed the logic for determining base_url_html.

  • Improved handling of base_url parsing using urlparse.


Changes walkthrough 📝

Relevant files
Bug fix
github_provider.py
Fix and enhance `base_url_html` logic                                       

pr_agent/git_providers/github_provider.py

  • Replaced logic for base_url_html determination.
  • Used urlparse for parsing base_url.
  • Adjusted handling of base_url to ensure correct HTML URL generation.
  • +2/-1     

    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

    URL Parsing Edge Case

    The new URL parsing logic assumes that API URLs always follow the pattern of having 'api.' prefix. This may not handle all GitHub Enterprise configurations where custom API URLs are used.

    base_url = urlparse(self.base_url)
    self.base_url_html = f"{base_url.scheme}://{base_url.netloc[4:] if base_url.netloc.startswith('api.') else 'https://github.com'}"

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Validate URL components before use

    Add validation for the base_url components after parsing to ensure they are not
    empty or malformed, preventing potential URL construction issues.

    pr_agent/git_providers/github_provider.py [40-41]

     base_url = urlparse(self.base_url)
    -self.base_url_html = f"{base_url.scheme}://{base_url.netloc[4:] if base_url.netloc.startswith('api.') else 'https://github.com'}"
    +if not base_url.scheme or not base_url.netloc:
    +    raise ValueError("Invalid base URL format")
    +self.base_url_html = f"{base_url.scheme}://{base_url.netloc[4:] if base_url.netloc.startswith('api.') else 'github.com'}"
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: Adding validation for URL components is crucial for preventing runtime errors and ensuring proper URL construction. This defensive programming approach would catch malformed URLs early.

    Medium
    General
    Preserve original URL scheme

    The URL scheme should be preserved from the original base_url instead of
    hardcoding 'https' in the fallback case. This ensures compatibility with
    different URL schemes (like 'http').

    pr_agent/git_providers/github_provider.py [41]

    -self.base_url_html = f"{base_url.scheme}://{base_url.netloc[4:] if base_url.netloc.startswith('api.') else 'https://github.com'}"
    +self.base_url_html = f"{base_url.scheme}://{base_url.netloc[4:] if base_url.netloc.startswith('api.') else 'github.com'}"
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion correctly identifies that hardcoding 'https' in the fallback case could cause issues with different URL schemes. Preserving the original scheme improves compatibility and correctness.

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

    @mrT23
    Copy link
    Collaborator

    mrT23 commented Mar 1, 2025

    for github cloud:
    base_url='https://api.github.com’
    ->
    base_url_html='https://github.com’

    for github server:
    base_url = "https://github.codium.ai/api/v3" (as clearly explained here: https://qodo-merge-docs.qodo.ai/installation/github/#action-for-github-enterprise-server)
    ->
    base_url_html='https://github.codium.ai/’

    These are the native apis for github cloud and server

    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