Skip to content

Conversation

Perdiga
Copy link
Collaborator

@Perdiga Perdiga commented Jul 16, 2025

No description provided.

@Copilot Copilot AI review requested due to automatic review settings July 16, 2025 01:28
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 functionality to analyze only changed files in Git repositories by comparing between Git references. This is useful for incremental analysis in CI/CD pipelines where you only want to analyze projects that contain changes.

  • Added command-line options --only-changed-files, --base-ref, and --target-ref for filtering analysis
  • Modified project detection logic to skip projects without changed files when filtering is enabled
  • Enhanced language detection to occur early in the process to avoid analyzing projects with no supported languages

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
src/codeql_wrapper/domain/entities/codeql_analysis.py Added new fields to CodeQLAnalysisRequest for Git-based filtering
src/codeql_wrapper/cli.py Added CLI options and validation for changed files analysis
src/codeql_wrapper/domain/use_cases/codeql_analysis_use_case.py Implemented core logic for filtering projects by changed files and improved language detection

Comment on lines 407 to 410
request.repository_path, LanguageType.NON_COMPILED
)
compiled_languages = self._detect_languages(
request.repository_path, LanguageType.COMPILED
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

Language detection is being performed on request.repository_path instead of the specific project_path. This will detect languages for the entire repository rather than the individual project, which may lead to incorrect results in monorepo scenarios.

Suggested change
request.repository_path, LanguageType.NON_COMPILED
)
compiled_languages = self._detect_languages(
request.repository_path, LanguageType.COMPILED
project_path, LanguageType.NON_COMPILED
)
compiled_languages = self._detect_languages(
project_path, LanguageType.COMPILED

Copilot uses AI. Check for mistakes.

Comment on lines 407 to 410
request.repository_path, LanguageType.NON_COMPILED
)
compiled_languages = self._detect_languages(
request.repository_path, LanguageType.COMPILED
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

Language detection is being performed on request.repository_path instead of the specific project_path. This will detect languages for the entire repository rather than the individual project, which may lead to incorrect results in monorepo scenarios.

Suggested change
request.repository_path, LanguageType.NON_COMPILED
)
compiled_languages = self._detect_languages(
request.repository_path, LanguageType.COMPILED
project_path, LanguageType.NON_COMPILED
)
compiled_languages = self._detect_languages(
project_path, LanguageType.COMPILED

Copilot uses AI. Check for mistakes.


def _detect_projects(
self, isMonorepo: bool, configData: Optional[dict], repository_path: Path
self, isMonorepo: bool, configData: Optional[dict], request: CodeQLAnalysisRequest
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

There are extra spaces before request parameter. Remove the extra space to maintain consistent formatting.

Suggested change
self, isMonorepo: bool, configData: Optional[dict], request: CodeQLAnalysisRequest
self, isMonorepo: bool, configData: Optional[dict], request: CodeQLAnalysisRequest

Copilot uses AI. Check for mistakes.

changed_file_path = Path(changed_file)
try:
# Check if the changed file is within the project directory
if str(relative_project_path) == "." or changed_file_path.is_relative_to(relative_project_path):
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

The is_relative_to method was introduced in Python 3.9. For better compatibility, consider using a string-based approach or add a version check since the fallback suggests older Python version support is intended.

Suggested change
if str(relative_project_path) == "." or changed_file_path.is_relative_to(relative_project_path):
if str(relative_project_path) == "." or str(changed_file_path).startswith(str(relative_project_path) + "/") or str(changed_file_path) == str(relative_project_path):

Copilot uses AI. Check for mistakes.

)

if request.only_changed_files:
self._logger.info(f"--only-changed-files will not be used in single project mode, all files will be analyzed")
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

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

[nitpick] The message should clarify that it's because the entire repository is treated as one project. Consider: "--only-changed-files is not applicable in single project mode; the entire repository will be analyzed"

Suggested change
self._logger.info(f"--only-changed-files will not be used in single project mode, all files will be analyzed")
self._logger.info(f"--only-changed-files is not applicable in single project mode because the entire repository is treated as a single project; all files will be analyzed.")

Copilot uses AI. Check for mistakes.

@Perdiga Perdiga merged commit 70ee349 into main Jul 16, 2025
5 checks passed
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.

1 participant