Skip to content

Conversation

Perdiga
Copy link
Collaborator

@Perdiga Perdiga commented Jul 17, 2025

No description provided.

@Copilot Copilot AI review requested due to automatic review settings July 17, 2025 19:06
Copilot

This comment was marked as outdated.

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 refactors Git information extraction and improves error handling in the analyze function. The main purpose is to improve the robustness of Git operations by switching from subprocess-based Git commands to using the GitPython library and restructuring the CLI architecture with proper separation of concerns.

Key changes include:

  • Replacement of subprocess-based Git operations with GitPython library for more reliable Git integration
  • Restructuring of the CLI module from a single file to a proper package structure with separate command modules
  • Enhancement of error handling in CodeQL installation process with fallback mechanisms

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/codeql_wrapper/infrastructure/language_detector.py Simplifies parameter types by removing Union[str, Path] and using Path directly
src/codeql_wrapper/infrastructure/git_utils.py Major refactor to use GitPython instead of subprocess calls for Git operations
src/codeql_wrapper/infrastructure/codeql_installer.py Improves error handling with fallback version when GitHub API fails
src/codeql_wrapper/entrypoints/cli/install.py New dedicated install command module with improved user feedback
src/codeql_wrapper/entrypoints/cli/cli.py New main CLI entry point with proper command registration
src/codeql_wrapper/entrypoints/cli/analyze.py New dedicated analyze command module with comprehensive validation
src/codeql_wrapper/entrypoints/cli/init.py Package initialization for CLI entrypoints
src/codeql_wrapper/entrypoints/init.py Package initialization for entrypoints
src/codeql_wrapper/domain/use_cases/sarif_upload_use_case.py Removes GitHub authentication stdin parameter from command
src/codeql_wrapper/domain/use_cases/codeql_analysis_use_case.py Updates Git integration to use new GitUtils class and improves project detection logic
src/codeql_wrapper/domain/entities/codeql_analysis.py Makes git_info a required field and reorders imports
src/codeql_wrapper/cli.py Removes legacy monolithic CLI file
src/codeql_wrapper/main.py Updates import path to new CLI structure
pyproject.toml Updates dependencies and script entry points for new CLI structure
Comments suppressed due to low confidence (3)

src/codeql_wrapper/infrastructure/git_utils.py:141

  • [nitpick] The error message could be more specific about what type of ref is expected and provide examples of valid environment variables.
            raise Exception("No ref provided or found in environment variables")

src/codeql_wrapper/infrastructure/git_utils.py:166

  • [nitpick] Similar to the previous error message, this could be more descriptive about what constitutes a valid base_ref and list the environment variables that are checked.
            raise Exception("No base_ref provided or found in environment variables")

src/codeql_wrapper/infrastructure/codeql_installer.py:160

  • [nitpick] The error message could be more helpful by suggesting how to install CodeQL or providing a link to installation instructions.
            raise Exception("CodeQL is not installed")

Comment on lines +41 to +43
repository=self.repo.remotes.origin.url.split("/")[-2]
+ "/"
+ self.repo.remotes.origin.url.split("/")[-1].replace(".git", ""),
Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

The repository name extraction using string splitting is fragile and could fail with different URL formats. Consider using urllib.parse or a more robust URL parsing method.

Suggested change
repository=self.repo.remotes.origin.url.split("/")[-2]
+ "/"
+ self.repo.remotes.origin.url.split("/")[-1].replace(".git", ""),
repository=self._extract_repository_name(self.repo.remotes.origin.url),

Copilot uses AI. Check for mistakes.

Comment on lines +44 to +51
instalation_message = (
f"CodeQL is already installed (version: {current_version})"
)
else:
instalation_message = f"CodeQL {installed_version} installed successfully!"

click.echo(
click.style("SUCCESS:", fg="green", bold=True) + f" {instalation_message}"
Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

There is a spelling error: 'instalation_message' should be 'installation_message'.

Suggested change
instalation_message = (
f"CodeQL is already installed (version: {current_version})"
)
else:
instalation_message = f"CodeQL {installed_version} installed successfully!"
click.echo(
click.style("SUCCESS:", fg="green", bold=True) + f" {instalation_message}"
installation_message = (
f"CodeQL is already installed (version: {current_version})"
)
else:
installation_message = f"CodeQL {installed_version} installed successfully!"
click.echo(
click.style("SUCCESS:", fg="green", bold=True) + f" {installation_message}"

Copilot uses AI. Check for mistakes.

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

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

Setting Git remote URL with authentication token in the URL could expose the token in Git logs or error messages. Consider using Git credential helpers or other secure authentication methods.

Copilot uses AI. Check for mistakes.

for config_index, project in enumerate(projects_config):
project_path = Path(project.get("path", ""))
project_path = Path(
request.git_info.working_dir, project.get("path", "")
Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

Using request.git_info.working_dir as the base path may cause issues if the working directory differs from the repository path. This could lead to incorrect project paths being constructed.

Suggested change
request.git_info.working_dir, project.get("path", "")
request.repository_path, project.get("path", "")

Copilot uses AI. Check for mistakes.

@Perdiga Perdiga merged commit 8fcfd41 into main Jul 21, 2025
2 checks passed
@fernandosantos-br fernandosantos-br deleted the feature/only-changed-files branch July 22, 2025 18:12
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.

3 participants