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,66 @@ 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+ required = True ,
836+ type = str ,
837+ help = 'Path to SCANOSS scan results file (JSON format) to analyze'
838+ )
839+
840+ # Line range prefix for GitLab file navigation
841+ # Enables clickable file references in the generated report that link to specific lines in GitLab
842+ p_gl_inspect_matches .add_argument (
843+ '-lpr' ,
844+ '--line-range-prefix' ,
845+ required = True ,
846+ type = str ,
847+ help = 'Base URL prefix for GitLab file links with line ranges (e.g., https://gitlab.com/org/project/-/blob/main)'
848+ )
849+
850+ # Output file argument - where to save the generated Markdown report
851+ p_gl_inspect_matches .add_argument (
852+ '--output' ,
853+ '-o' ,
854+ required = False ,
855+ type = str ,
856+ help = 'Output file path for the generated Markdown report (default: stdout)'
857+ )
858+
798859 # TODO Move to the command call def location
799860 # RAW results
800861 p_inspect_raw_undeclared .set_defaults (func = inspect_undeclared )
@@ -808,6 +869,8 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
808869 p_inspect_legacy_component_summary .set_defaults (func = inspect_component_summary )
809870 # Dependency Track
810871 p_inspect_dt_project_violation .set_defaults (func = inspect_dep_track_project_violations )
872+ # GitLab
873+ p_gl_inspect_matches .set_defaults (func = inspect_gitlab_matches )
811874
812875 # =========================================================================
813876 # END INSPECT SUBCOMMAND CONFIGURATION
@@ -1157,6 +1220,7 @@ def setup_args() -> None: # noqa: PLR0912, PLR0915
11571220 p_inspect_legacy_license_summary ,
11581221 p_inspect_legacy_component_summary ,
11591222 p_inspect_dt_project_violation ,
1223+ p_gl_inspect_matches ,
11601224 c_provenance ,
11611225 p_folder_scan ,
11621226 p_folder_hash ,
@@ -1613,7 +1677,7 @@ def convert(parser, args):
16131677 print_stderr ('Producing CSV report...' )
16141678 csvo = CsvOutput (debug = args .debug , output_file = args .output )
16151679 success = csvo .produce_from_file (args .input )
1616- elif args .format == 'glcodequality ' :
1680+ elif args .format == 'glc-codequality ' :
16171681 if not args .quiet :
16181682 print_stderr ('Producing Gitlab code quality report...' )
16191683 glcCodeQuality = GitLabQualityReport (debug = args .debug , output_file = args .output )
@@ -1891,6 +1955,58 @@ def inspect_dep_track_project_violations(parser, args):
18911955 sys .exit (1 )
18921956
18931957
1958+ def inspect_gitlab_matches (parser , args ):
1959+ """
1960+ Handle GitLab matches summary inspection command.
1961+
1962+ Analyzes SCANOSS scan results and generates a GitLab-compatible Markdown summary
1963+ report of component matches. The report includes match details, file locations,
1964+ and optionally clickable links to source files in GitLab repositories.
1965+
1966+ This command processes SCANOSS scan output and creates human-readable Markdown.
1967+
1968+ Parameters
1969+ ----------
1970+ args : Namespace
1971+ Parsed command line arguments containing:
1972+ - input: Path to SCANOSS scan results file (JSON format) to analyze
1973+ - line_range_prefix: Base URL prefix for generating GitLab file links with line ranges
1974+ (e.g., 'https://gitlab.com/org/project/-/blob/main')
1975+ - output: Optional output file path for the generated Markdown report (default: stdout)
1976+ - debug: Enable debug output for troubleshooting
1977+ - trace: Enable trace-level logging
1978+ - quiet: Suppress informational messages
1979+
1980+ Notes
1981+ -----
1982+ - The output is formatted in Markdown for optimal display in GitLab
1983+ - Line range prefix enables clickable file references in the report
1984+ - If output is not specified, the report is written to stdout
1985+ """
1986+ # Initialize output file if specified (create/truncate)
1987+ if args .output :
1988+ initialise_empty_file (args .output )
1989+
1990+ try :
1991+ # Create GitLab matches summary generator with configuration
1992+ match_summary = MatchSummary (
1993+ debug = args .debug ,
1994+ trace = args .trace ,
1995+ quiet = args .quiet ,
1996+ scanoss_results_path = args .input , # Path to SCANOSS JSON results
1997+ output = args .output , # Output file path or None for stdout
1998+ line_range_prefix = args .line_range_prefix , # GitLab URL prefix for file links
1999+ )
2000+
2001+ # Execute the summary generation
2002+ match_summary .run ()
2003+ except Exception as e :
2004+ # Handle any errors during report generation
2005+ print_stderr (e )
2006+ if args .debug :
2007+ traceback .print_exc ()
2008+ sys .exit (1 )
2009+
18942010# =============================================================================
18952011# END INSPECT COMMAND HANDLERS
18962012# =============================================================================
0 commit comments