Skip to content

Refactor credential injection in git URL to use URL parsing library #1349

Description

@sourcery-ai

Currently, the code responsible for injecting credentials into the REPOLIST_GIT URL simply replaces 'https://' with a version containing the token. This approach may not handle all possible URL formats and could fail or produce invalid URLs in cases where:

  • The URL does not start with 'https://'
  • The URL already includes credentials
  • There are other edge cases in URL formatting

To make credential injection more robust and secure, we should refactor this logic to use a URL parsing library (such as Python's urllib.parse). This will allow us to safely inject credentials only when appropriate (e.g., when the scheme is 'https' and no credentials are present), and reconstruct the URL in a standards-compliant way.

Suggested action items:

  • Refactor the credential injection logic to use urllib.parse for parsing and reconstructing the URL.
  • Ensure credentials are only injected when the scheme is 'https' and no credentials are already present.
  • Add tests to cover various URL formats and edge cases.

This will improve the reliability and security of the repository cloning process, especially when using personal access tokens or other credentials.


I created this issue for @psegedy from #1347 (comment).

Tips and commands

Getting Help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions