4040)
4141from scanoss .inspection .raw .component_summary import ComponentSummary
4242from scanoss .inspection .raw .license_summary import LicenseSummary
43+ from scanoss .inspection .raw .match_summary import MatchSummary
4344from scanoss .scanners .container_scanner import (
4445 DEFAULT_SYFT_COMMAND ,
4546 DEFAULT_SYFT_TIMEOUT ,
7374from .csvoutput import CsvOutput
7475from .cyclonedx import CycloneDx
7576from .filecount import FileCount
77+ from .gitlabqualityreport import GitLabQualityReport
7678from .inspection .raw .copyleft import Copyleft
7779from .inspection .raw .undeclared_component import UndeclaredComponent
7880from .results import Results
8587from .spdxlite import SpdxLite
8688from .threadeddependencies import SCOPE
8789from .utils .file import validate_json_file
88- from .gitlabqualityreport import GitLabQualityReport
8990
9091HEADER_PARTS_COUNT = 2
9192
@@ -284,7 +285,7 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
284285 '--format' ,
285286 '-f' ,
286287 type = str ,
287- choices = ['cyclonedx' , 'spdxlite' , 'csv' , 'glcodequality ' ],
288+ choices = ['cyclonedx' , 'spdxlite' , 'csv' , 'glc-codequality ' ],
288289 default = 'spdxlite' ,
289290 help = 'Output format (optional - default: spdxlite)' ,
290291 )
@@ -795,6 +796,64 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
795796 help = 'Timeout (in seconds) for API communication (optional - default 300 sec)' ,
796797 )
797798
799+
800+ # ==============================================================================
801+ # GitLab Integration Parser
802+ # ==============================================================================
803+ # Main parser for GitLab-specific inspection commands and report generation
804+ p_gitlab_sub = p_inspect_sub .add_parser (
805+ 'gitlab' ,
806+ aliases = ['glc' ],
807+ description = 'Generate GitLab-compatible reports from SCANOSS scan results (Markdown summaries)' ,
808+ help = 'Generate GitLab integration reports' ,
809+ )
810+
811+ # GitLab sub-commands parser
812+ # Provides access to different GitLab report formats and inspection tools
813+ p_gitlab_sub_parser = p_gitlab_sub .add_subparsers (
814+ title = 'GitLab Report Types' ,
815+ dest = 'subparser_subcmd' ,
816+ description = 'Available GitLab report formats for scan result analysis' ,
817+ help = 'Select the type of GitLab report to generate' ,
818+ )
819+
820+ # ==============================================================================
821+ # GitLab Matches Summary Command
822+ # ==============================================================================
823+ # Analyzes scan results and generates a GitLab-compatible Markdown summary
824+ p_gl_inspect_matches = p_gitlab_sub_parser .add_parser (
825+ 'matches' ,
826+ aliases = ['ms' ],
827+ description = 'Generate a Markdown summary report of scan matches for GitLab integration' ,
828+ help = 'Generate Markdown summary report of scan matches' ,
829+ )
830+
831+ # Input file argument - SCANOSS scan results in JSON format
832+ p_gl_inspect_matches .add_argument (
833+ '-i' ,
834+ '--input' ,
835+ nargs = '?' ,
836+ help = 'Path to SCANOSS scan results file (JSON format) to analyze'
837+ )
838+
839+ # Line range prefix for GitLab file navigation
840+ # Enables clickable file references in the generated report that link to specific lines in GitLab
841+ p_gl_inspect_matches .add_argument (
842+ '-lpr' ,
843+ '--line-range-prefix' ,
844+ nargs = '?' ,
845+ help = 'Base URL prefix for GitLab file links with line ranges (e.g., https://gitlab.com/org/project/-/blob/main)'
846+ )
847+
848+ # Output file argument - where to save the generated Markdown report
849+ p_gl_inspect_matches .add_argument (
850+ '--output' ,
851+ '-o' ,
852+ required = False ,
853+ type = str ,
854+ help = 'Output file path for the generated Markdown report (default: stdout)'
855+ )
856+
798857 # TODO Move to the command call def location
799858 # RAW results
800859 p_inspect_raw_undeclared .set_defaults (func = inspect_undeclared )
@@ -809,6 +868,9 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
809868 # Dependency Track
810869 p_inspect_dt_project_violation .set_defaults (func = inspect_dep_track_project_violations )
811870
871+ # GitLab
872+ p_gl_inspect_matches .set_defaults (func = inspect_gitlab_matches )
873+
812874 # =========================================================================
813875 # END INSPECT SUBCOMMAND CONFIGURATION
814876 # =========================================================================
@@ -1157,6 +1219,7 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
11571219 p_inspect_legacy_license_summary ,
11581220 p_inspect_legacy_component_summary ,
11591221 p_inspect_dt_project_violation ,
1222+ p_gl_inspect_matches ,
11601223 c_provenance ,
11611224 p_folder_scan ,
11621225 p_folder_hash ,
@@ -1891,6 +1954,58 @@ def inspect_dep_track_project_violations(parser, args):
18911954 sys .exit (1 )
18921955
18931956
1957+ def inspect_gitlab_matches (parser , args ):
1958+ """
1959+ Handle GitLab matches summary inspection command.
1960+
1961+ Analyzes SCANOSS scan results and generates a GitLab-compatible Markdown summary
1962+ report of component matches. The report includes match details, file locations,
1963+ and optionally clickable links to source files in GitLab repositories.
1964+
1965+ This command processes SCANOSS scan output and creates human-readable Markdown.
1966+
1967+ Parameters
1968+ ----------
1969+ args : Namespace
1970+ Parsed command line arguments containing:
1971+ - input: Path to SCANOSS scan results file (JSON format) to analyze
1972+ - line_range_prefix: Base URL prefix for generating GitLab file links with line ranges
1973+ (e.g., 'https://gitlab.com/org/project/-/blob/main')
1974+ - output: Optional output file path for the generated Markdown report (default: stdout)
1975+ - debug: Enable debug output for troubleshooting
1976+ - trace: Enable trace-level logging
1977+ - quiet: Suppress informational messages
1978+
1979+ Notes
1980+ -----
1981+ - The output is formatted in Markdown for optimal display in GitLab
1982+ - Line range prefix enables clickable file references in the report
1983+ - If output is not specified, the report is written to stdout
1984+ """
1985+ # Initialize output file if specified (create/truncate)
1986+ if args .output :
1987+ initialise_empty_file (args .output )
1988+
1989+ try :
1990+ # Create GitLab matches summary generator with configuration
1991+ match_summary = MatchSummary (
1992+ debug = args .debug ,
1993+ trace = args .trace ,
1994+ quiet = args .quiet ,
1995+ scanoss_results_path = args .input , # Path to SCANOSS JSON results
1996+ output = args .output , # Output file path or None for stdout
1997+ line_range_prefix = args .line_range_prefix , # GitLab URL prefix for file links
1998+ )
1999+
2000+ # Execute the summary generation
2001+ match_summary .run ()
2002+ except Exception as e :
2003+ # Handle any errors during report generation
2004+ print_stderr (e )
2005+ if args .debug :
2006+ traceback .print_exc ()
2007+ sys .exit (1 )
2008+
18942009# =============================================================================
18952010# END INSPECT COMMAND HANDLERS
18962011# =============================================================================
0 commit comments