-
Notifications
You must be signed in to change notification settings - Fork 24
Chore/refactor inspect module #161
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ed6e007
chore:SP-3607 refactor inspect module
agustingroh 1817bd6
chore: updates CHANGELOG.md file
agustingroh 139f957
chore: Adds debug and trace logging to GitLab quality report and matc…
agustingroh 1b45692
chore: Adds local linter to Makefile
agustingroh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,4 +22,4 @@ | |
| THE SOFTWARE. | ||
| """ | ||
|
|
||
| __version__ = '1.40.0' | ||
| __version__ = '1.40.1' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,16 +74,21 @@ def __init__(self, debug: bool = False, trace: bool = False, quiet: bool = False | |
| Initialise the GitLabCodeQuality class | ||
| """ | ||
| super().__init__(debug, trace, quiet) | ||
| self.print_trace(f"GitLabQualityReport initialized with debug={debug}, trace={trace}, quiet={quiet}") | ||
|
|
||
|
|
||
| def _get_code_quality(self, file_name: str, result: dict) -> CodeQuality or None: | ||
| self.print_trace(f"_get_code_quality called for file: {file_name}") | ||
| self.print_trace(f"Processing result: {result}") | ||
|
|
||
| if not result.get('file_hash'): | ||
| self.print_debug(f"Warning: no hash found for result: {result}") | ||
| return None | ||
|
|
||
| if result.get('id') == 'file': | ||
| self.print_debug(f"Processing file match for: {file_name}") | ||
| description = f"File match found in: {file_name}" | ||
| return CodeQuality( | ||
| code_quality = CodeQuality( | ||
| description=description, | ||
| check_name=file_name, | ||
| fingerprint=result.get('file_hash'), | ||
|
|
@@ -95,17 +100,21 @@ def _get_code_quality(self, file_name: str, result: dict) -> CodeQuality or None | |
| ) | ||
| ) | ||
| ) | ||
| self.print_trace(f"Created file CodeQuality object: {code_quality}") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this to be traced? |
||
| return code_quality | ||
|
|
||
| if not result.get('lines'): | ||
| self.print_debug(f"Warning: No lines found for result: {result}") | ||
| return None | ||
| lines = scanoss_scan_results_utils.get_lines(result.get('lines')) | ||
| self.print_trace(f"Extracted lines: {lines}") | ||
| if len(lines) == 0: | ||
| self.print_debug(f"Warning: empty lines for result: {result}") | ||
| return None | ||
| end_line = lines[len(lines) - 1] if len(lines) > 1 else lines[0] | ||
| description = f"Snippet found in: {file_name} - lines {lines[0]}-{end_line}" | ||
| return CodeQuality( | ||
| self.print_debug(f"Processing snippet match for: {file_name}, lines: {lines[0]}-{end_line}") | ||
| code_quality = CodeQuality( | ||
| description=description, | ||
| check_name=file_name, | ||
| fingerprint=result.get('file_hash'), | ||
|
|
@@ -117,35 +126,47 @@ def _get_code_quality(self, file_name: str, result: dict) -> CodeQuality or None | |
| ) | ||
| ) | ||
| ) | ||
| self.print_trace(f"Created snippet CodeQuality object: {code_quality}") | ||
| return code_quality | ||
|
|
||
| def _write_output(self, data: list[CodeQuality], output_file: str = None) -> bool: | ||
| """Write the Gitlab Code Quality Report to output.""" | ||
| self.print_trace(f"_write_output called with {len(data)} items, output_file: {output_file}") | ||
| try: | ||
| json_data = [item.to_dict() for item in data] | ||
| self.print_trace(f"JSON data: {json_data}") | ||
| file = open(output_file, 'w') if output_file else sys.stdout | ||
| print(json.dumps(json_data, indent=2), file=file) | ||
| if output_file: | ||
| file.close() | ||
| self.print_debug(f"Wrote output to file: {output_file}") | ||
| else: | ||
| self.print_debug("Wrote output to 'stdout'") | ||
| return True | ||
| except Exception as e: | ||
| self.print_stderr(f'Error writing output: {str(e)}') | ||
| return False | ||
|
|
||
| def _produce_from_json(self, data: dict, output_file: str = None) -> bool: | ||
| self.print_trace(f"_produce_from_json called with output_file: {output_file}") | ||
| self.print_debug(f"Processing {len(data)} files from JSON data") | ||
| code_quality = [] | ||
| for file_name, results in data.items(): | ||
| self.print_trace(f"Processing file: {file_name} with {len(results)} results") | ||
| for result in results: | ||
| if not result.get('id'): | ||
| self.print_debug(f"Warning: No ID found for result: {result}") | ||
| continue | ||
| if result.get('id') != 'snippet' and result.get('id') != 'file': | ||
| self.print_debug(f"Skipping non-snippet/file match: {result}") | ||
| self.print_debug(f"Skipping non-snippet/file match: {file_name}, id: '{result['id']}'") | ||
| continue | ||
| code_quality_item = self._get_code_quality(file_name, result) | ||
| if code_quality_item: | ||
| code_quality.append(code_quality_item) | ||
| self.print_trace(f"Added code quality item for {file_name}") | ||
| else: | ||
| self.print_debug(f"Warning: No Code Quality found for result: {result}") | ||
| self.print_debug(f"Generated {len(code_quality)} code quality items") | ||
| self._write_output(data=code_quality,output_file=output_file) | ||
| return True | ||
|
|
||
|
|
@@ -156,11 +177,15 @@ def _produce_from_str(self, json_str: str, output_file: str = None) -> bool: | |
| :param output_file: Output file (optional) | ||
| :return: True if successful, False otherwise | ||
| """ | ||
| self.print_trace(f"_produce_from_str called with output_file: {output_file}") | ||
| if not json_str: | ||
| self.print_stderr('ERROR: No JSON string provided to parse.') | ||
| return False | ||
| self.print_debug(f"Parsing JSON string of length: {len(json_str)}") | ||
| try: | ||
| data = json.loads(json_str) | ||
| self.print_debug("Successfully parsed JSON data") | ||
| self.print_trace(f"Parsed data structure: {type(data)}") | ||
| except Exception as e: | ||
| self.print_stderr(f'ERROR: Problem parsing input JSON: {e}') | ||
| return False | ||
|
|
@@ -174,12 +199,16 @@ def produce_from_file(self, json_file: str, output_file: str = None) -> bool: | |
| :param output_file: | ||
| :return: True if successful, False otherwise | ||
| """ | ||
| self.print_trace(f"produce_from_file called with json_file: {json_file}, output_file: {output_file}") | ||
| self.print_debug(f"Input JSON file: {json_file}, output_file: {output_file}") | ||
| if not json_file: | ||
| self.print_stderr('ERROR: No JSON file provided to parse.') | ||
| return False | ||
| if not os.path.isfile(json_file): | ||
| self.print_stderr(f'ERROR: JSON file does not exist or is not a file: {json_file}') | ||
| return False | ||
| self.print_debug(f"Reading JSON file: {json_file}") | ||
| with open(json_file, 'r') as f: | ||
| success = self._produce_from_str(f.read(), output_file) | ||
| json_content = f.read() | ||
| success = self._produce_from_str(json_content, output_file) | ||
| return success | ||
File renamed without changes.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If we use ruff's pre-commit hook we wouldn't need all these make commands