Skip to content

Conversation

fernandosantos-br
Copy link
Collaborator

No description provided.

@Copilot Copilot AI review requested due to automatic review settings July 22, 2025 18:09
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds GitHub token authentication support to improve the reliability of fetching pull request references in the Git utilities module. The authentication is implemented conditionally based on the presence of a GITHUB_TOKEN environment variable.

Comment on lines +88 to 97
origin.set_url(
(
f"https://x-access-token:{os.getenv('GITHUB_TOKEN')}"
f"@github.com/{origin.url.split('/')[-2]}/"
f"{origin.url.split('/')[-1]}"
)
)

# Equivalent to: git fetch origin refs/pull/xx/merge
origin.fetch(current_ref)
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying the origin URL permanently could expose the token in subsequent operations and logs. Consider using a temporary authentication method or creating a separate remote for authenticated operations.

Suggested change
origin.set_url(
(
f"https://x-access-token:{os.getenv('GITHUB_TOKEN')}"
f"@github.com/{origin.url.split('/')[-2]}/"
f"{origin.url.split('/')[-1]}"
)
)
# Equivalent to: git fetch origin refs/pull/xx/merge
origin.fetch(current_ref)
temp_url = (
f"https://x-access-token:{os.getenv('GITHUB_TOKEN')}"
f"@github.com/{origin.url.split('/')[-2]}/"
f"{origin.url.split('/')[-1]}"
)
self.logger.debug(f"Using temporary URL for fetch: {temp_url}")
# Equivalent to: git fetch <temp_url> refs/pull/xx/merge
self.repo.git.fetch(temp_url, current_ref)

Copilot uses AI. Check for mistakes.

Comment on lines +91 to +92
f"@github.com/{origin.url.split('/')[-2]}/"
f"{origin.url.split('/')[-1]}"
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL parsing using string splitting is brittle and may fail for different URL formats (SSH, different protocols). Consider using urllib.parse or a more robust URL parsing method.

Suggested change
f"@github.com/{origin.url.split('/')[-2]}/"
f"{origin.url.split('/')[-1]}"
f"@{parsed_url.netloc}/{'/'.join(path_parts)}"

Copilot uses AI. Check for mistakes.

Comment on lines +84 to +90
if os.getenv("GITHUB_TOKEN"):
self.logger.debug(
"Setting up GitHub token authentication for fetch"
)
origin.set_url(
(
f"https://x-access-token:{os.getenv('GITHUB_TOKEN')}"
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GitHub token is retrieved twice with os.getenv('GITHUB_TOKEN'), but the second call could return None if the environment variable was removed between calls. Store the token in a variable after the initial check.

Suggested change
if os.getenv("GITHUB_TOKEN"):
self.logger.debug(
"Setting up GitHub token authentication for fetch"
)
origin.set_url(
(
f"https://x-access-token:{os.getenv('GITHUB_TOKEN')}"
github_token = os.getenv("GITHUB_TOKEN")
if github_token:
self.logger.debug(
"Setting up GitHub token authentication for fetch"
)
origin.set_url(
(
f"https://x-access-token:{github_token}"

Copilot uses AI. Check for mistakes.

@fernandosantos-br fernandosantos-br merged commit fadc35f into main Jul 22, 2025
5 of 8 checks passed
@fernandosantos-br fernandosantos-br deleted the feature/fix-git-login-token branch July 22, 2025 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants