Skip to content

Commit 38aebf0

Browse files
committed
chore:implements Rawbase methods on ComponentSummary and LicenseSummary commands
1 parent 2d48fe3 commit 38aebf0

File tree

5 files changed

+123
-13
lines changed

5 files changed

+123
-13
lines changed

src/scanoss/cli.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,11 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
12721272
) and not args.subparsercmd:
12731273
parser.parse_args([args.subparser, '--help']) # Force utils helps to be displayed
12741274
sys.exit(1)
1275-
elif (args.subparser in 'inspect') and (args.subparsercmd in ('raw', 'dt')) and (args.subparser_subcmd is None):
1275+
elif (
1276+
(args.subparser in 'inspect')
1277+
and (args.subparsercmd in ('raw', 'dt', 'glc', 'gitlab'))
1278+
and (args.subparser_subcmd is None)
1279+
):
12761280
parser.parse_args([args.subparser, args.subparsercmd, '--help']) # Force utils helps to be displayed
12771281
sys.exit(1)
12781282
args.func(parser, args) # Execute the function associated with the sub-command
@@ -1696,8 +1700,8 @@ def convert(parser, args):
16961700
elif args.format == 'glc-codequality':
16971701
if not args.quiet:
16981702
print_stderr('Producing Gitlab code quality report...')
1699-
glcCodeQuality = GitLabQualityReport(debug=args.debug, trace=args.trace, quiet=args.quiet)
1700-
success = glcCodeQuality.produce_from_file(args.input, output_file=args.output)
1703+
glc_code_quality = GitLabQualityReport(debug=args.debug, trace=args.trace, quiet=args.quiet)
1704+
success = glc_code_quality.produce_from_file(args.input, output_file=args.output)
17011705
else:
17021706
print_stderr(f'ERROR: Unknown output format (--format): {args.format}')
17031707
if not success:
@@ -1971,9 +1975,9 @@ def inspect_dep_track_project_violations(parser, args):
19711975
sys.exit(1)
19721976

19731977

1974-
def inspect_gitlab_matches(parser, args):
1978+
def inspect_gitlab_matches(parser,args):
19751979
"""
1976-
Handle GitLab matches summary inspection command.
1980+
Handle GitLab matches the summary inspection command.
19771981
19781982
Analyzes SCANOSS scan results and generates a GitLab-compatible Markdown summary
19791983
report of component matches. The report includes match details, file locations,
@@ -1983,6 +1987,8 @@ def inspect_gitlab_matches(parser, args):
19831987
19841988
Parameters
19851989
----------
1990+
parser : ArgumentParser
1991+
Command line parser object for help display
19861992
args : Namespace
19871993
Parsed command line arguments containing:
19881994
- input: Path to SCANOSS scan results file (JSON format) to analyze
@@ -1999,6 +2005,15 @@ def inspect_gitlab_matches(parser, args):
19992005
- Line range prefix enables clickable file references in the report
20002006
- If output is not specified, the report is written to stdout
20012007
"""
2008+
2009+
if args.input is None:
2010+
parser.parse_args([args.subparser, '-h'])
2011+
sys.exit(1)
2012+
2013+
if args.line_range_prefix is None:
2014+
parser.parse_args([args.subparser, '-h'])
2015+
sys.exit(1)
2016+
20022017
# Initialize output file if specified (create/truncate)
20032018
if args.output:
20042019
initialise_empty_file(args.output)

src/scanoss/gitlabqualityreport.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from .utils import scanoss_scan_results_utils
3232

3333

34-
3534
@dataclass
3635
class Lines:
3736
begin: int
@@ -152,7 +151,7 @@ def _produce_from_json(self, data: dict, output_file: str = None) -> bool:
152151

153152
def _produce_from_str(self, json_str: str, output_file: str = None) -> bool:
154153
"""
155-
Produce Gitlab Code Quality Reportoutput from input JSON string
154+
Produce Gitlab Code Quality Report output from input JSON string
156155
:param json_str: input JSON string
157156
:param output_file: Output file (optional)
158157
:return: True if successful, False otherwise

src/scanoss/inspection/raw/component_summary.py

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,57 @@
2121
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
THE SOFTWARE.
2323
"""
24-
2524
import json
26-
from typing import Dict, Any
25+
from typing import Any
2726

28-
from .raw_base import RawBase
2927
from ..policy_check import T
28+
from .raw_base import RawBase
3029

3130

3231
class ComponentSummary(RawBase):
3332

33+
def _json(self, data: dict[str,Any]) -> dict[str,Any]:
34+
"""
35+
Format component summary data as JSON.
36+
37+
This method returns the component summary data in its original JSON structure
38+
without any transformation. The data can be directly serialized to JSON format.
39+
40+
:param data: Dictionary containing component summary information including:
41+
- components: List of component-license pairs with status and metadata
42+
- totalComponents: Total number of unique components
43+
- undeclaredComponents: Number of components with 'pending' status
44+
- declaredComponents: Number of components with 'identified' status
45+
- totalFilesDetected: Total count of files where components were detected
46+
- totalFilesUndeclared: Count of files with undeclared components
47+
- totalFilesDeclared: Count of files with declared components
48+
:return: The same data dictionary, ready for JSON serialization
49+
"""
50+
return data
51+
52+
def _markdown(self, data: list[T]) -> dict[str, Any]:
53+
"""
54+
Format component summary data as Markdown (not yet implemented).
55+
56+
This method is intended to convert component summary data into a human-readable
57+
Markdown format with tables and formatted sections.
58+
59+
:param data: List of component summary items to format
60+
:return: Dictionary containing formatted Markdown output
61+
"""
62+
pass
63+
64+
def _jira_markdown(self, data: list[T]) -> dict[str, Any]:
65+
"""
66+
Format component summary data as Jira-flavored Markdown (not yet implemented).
67+
68+
This method is intended to convert component summary data into Jira-compatible
69+
Markdown format, which may include Jira-specific syntax for tables and formatting.
70+
71+
:param data: List of component summary items to format
72+
:return: Dictionary containing Jira-formatted Markdown output
73+
"""
74+
pass
3475

3576
def _get_component_summary_from_components(self, scan_components: list)-> dict:
3677
"""
@@ -88,10 +129,16 @@ def _get_components(self):
88129
self._get_components_data(self.results, components)
89130
return self._convert_components_to_list(components)
90131

132+
def _format(self, component_summary) -> str:
133+
# TODO: Implement formatter to support dynamic outputs
134+
json_data = self._json(component_summary)
135+
return json.dumps(json_data, indent=2)
136+
91137
def run(self):
92138
components = self._get_components()
93139
component_summary = self._get_component_summary_from_components(components)
94-
self.print_to_file_or_stdout(json.dumps(component_summary, indent=2), self.output)
140+
output = self._format(component_summary)
141+
self.print_to_file_or_stdout(output, self.output)
95142
return component_summary
96143
#
97144
# End of ComponentSummary Class

src/scanoss/inspection/raw/license_summary.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"""
2424

2525
import json
26+
from typing import Any
2627

28+
from ..policy_check import T
2729
from .raw_base import RawBase
2830

2931

@@ -36,6 +38,46 @@ class LicenseSummary(RawBase):
3638
information, providing detailed summaries including copyleft analysis and license statistics.
3739
"""
3840

41+
def _json(self, data: dict[str,Any]) -> dict[str, Any]:
42+
"""
43+
Format license summary data as JSON (not yet implemented).
44+
45+
This method is intended to return the license summary data in JSON structure
46+
for serialization. The data should include license information with copyleft
47+
analysis and license statistics.
48+
49+
:param data: List of license summary items to format
50+
:return: Dictionary containing license summary information including:
51+
- licenses: List of detected licenses with SPDX IDs, URLs, and copyleft status
52+
- detectedLicenses: Total number of unique licenses
53+
- detectedLicensesWithCopyleft: Count of licenses marked as copyleft
54+
"""
55+
return data
56+
57+
def _markdown(self, data: list[T]) -> dict[str, Any]:
58+
"""
59+
Format license summary data as Markdown (not yet implemented).
60+
61+
This method is intended to convert license summary data into a human-readable
62+
Markdown format with tables and formatted sections.
63+
64+
:param data: List of license summary items to format
65+
:return: Dictionary containing formatted Markdown output
66+
"""
67+
pass
68+
69+
def _jira_markdown(self, data: list[T]) -> dict[str, Any]:
70+
"""
71+
Format license summary data as Jira-flavored Markdown (not yet implemented).
72+
73+
This method is intended to convert license summary data into Jira-compatible
74+
Markdown format, which may include Jira-specific syntax for tables and formatting.
75+
76+
:param data: List of license summary items to format
77+
:return: Dictionary containing Jira-formatted Markdown output
78+
"""
79+
pass
80+
3981
# Define required license fields as class constants
4082
REQUIRED_LICENSE_FIELDS = ['spdxid', 'url', 'copyleft', 'source']
4183

@@ -131,10 +173,16 @@ def _get_components(self):
131173
self._get_dependencies_data(self.results, components)
132174
return self._convert_components_to_list(components)
133175

176+
def _format(self, license_summary) -> str:
177+
# TODO: Implement formatter to support dynamic outputs
178+
json_data = self._json(license_summary)
179+
return json.dumps(json_data, indent=2)
180+
134181
def run(self):
135182
components = self._get_components()
136183
license_summary = self._get_licenses_summary_from_components(components)
137-
self.print_to_file_or_stdout(json.dumps(license_summary, indent=2), self.output)
184+
output = self._format(license_summary)
185+
self.print_to_file_or_stdout(output, self.output)
138186
return license_summary
139187
#
140188
# End of LicenseSummary Class

src/scanoss/inspection/raw/match_summary.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __init__( # noqa: PLR0913
9090
:param scanoss_results_path: Path to SCANOSS scan results file in JSON format
9191
:param output: Output file path for the generated Markdown report (default: stdout)
9292
"""
93-
super().__init__(debug, trace, quiet)
93+
super().__init__(debug=debug, trace=trace, quiet=quiet)
9494
self.scanoss_results_path = scanoss_results_path
9595
self.line_range_prefix = line_range_prefix
9696
self.output = output
@@ -185,6 +185,7 @@ def _get_matches_summary(self) -> ComponentMatchSummary:
185185
for result in results:
186186
# Skip non-matches
187187
if result.get('id') == "none":
188+
self.print_debug(f'Skipping non-match for file {file_name}')
188189
continue
189190

190191
# Validate required fields

0 commit comments

Comments
 (0)