-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add options for analyzing only changed files with Git references #58
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
Conversation
There was a problem hiding this 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-reffor 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 |
| request.repository_path, LanguageType.NON_COMPILED | ||
| ) | ||
| compiled_languages = self._detect_languages( | ||
| request.repository_path, LanguageType.COMPILED |
Copilot
AI
Jul 16, 2025
There was a problem hiding this comment.
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.
| 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 |
| request.repository_path, LanguageType.NON_COMPILED | ||
| ) | ||
| compiled_languages = self._detect_languages( | ||
| request.repository_path, LanguageType.COMPILED |
Copilot
AI
Jul 16, 2025
There was a problem hiding this comment.
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.
| 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 |
|
|
||
| def _detect_projects( | ||
| self, isMonorepo: bool, configData: Optional[dict], repository_path: Path | ||
| self, isMonorepo: bool, configData: Optional[dict], request: CodeQLAnalysisRequest |
Copilot
AI
Jul 16, 2025
There was a problem hiding this comment.
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.
| self, isMonorepo: bool, configData: Optional[dict], request: CodeQLAnalysisRequest | |
| self, isMonorepo: bool, configData: Optional[dict], request: CodeQLAnalysisRequest |
| 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): |
Copilot
AI
Jul 16, 2025
There was a problem hiding this comment.
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.
| 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): |
| ) | ||
|
|
||
| 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") |
Copilot
AI
Jul 16, 2025
There was a problem hiding this comment.
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"
| 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.") |
No description provided.