From d76510c0922a092afdbe133f9c39a886f44cfd84 Mon Sep 17 00:00:00 2001 From: matteogreek Date: Tue, 25 Jul 2023 11:41:27 +0200 Subject: [PATCH] Add prospector run parameters in JSON report. Add cli option to exclude diff. --- prospector/cli/main.py | 35 +++++++++++++++++--------------- prospector/core/report.py | 25 ++++++++++++++++++++--- prospector/util/config_parser.py | 6 ++++++ 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/prospector/cli/main.py b/prospector/cli/main.py index 0ef9e7217..633754cdb 100644 --- a/prospector/cli/main.py +++ b/prospector/cli/main.py @@ -88,24 +88,26 @@ def main(argv): # noqa: C901 logger.debug("Vulnerability ID: " + config.vuln_id) - results, advisory_record = prospector( - vulnerability_id=config.vuln_id, - repository_url=config.repository, - publication_date=config.pub_date, - vuln_descr=config.description, - version_interval=config.version_interval, - modified_files=config.modified_files, - advisory_keywords=config.keywords, - use_nvd=config.use_nvd, + params = { + "vulnerability_id": config.vuln_id, + "repository_url": config.repository, + "publication_date": config.pub_date, + "vuln_descr": config.description, + "version_interval": config.version_interval, + "modified_files": config.modified_files, + "advisory_keywords": config.keywords, + "use_nvd": config.use_nvd, # fetch_references=config.fetch_references, - backend_address=config.backend, - use_backend=config.use_backend, - git_cache=config.git_cache, - limit_candidates=config.max_candidates, + "backend_address": config.backend, + "use_backend": config.use_backend, + "git_cache": config.git_cache, + "limit_candidates": config.max_candidates, # ignore_adv_refs=config.ignore_refs, - use_llm_repository_url=config.llm_service.use_llm_repository_url, - enabled_rules=config.enabled_rules, - ) + "use_llm_repository_url": config.llm_service.use_llm_repository_url, + "enabled_rules": config.enabled_rules, + } + + results, advisory_record = prospector(**params) if config.preprocess_only: return @@ -115,6 +117,7 @@ def main(argv): # noqa: C901 advisory_record, config.report, config.report_filename, + params, config.report_diff, ) diff --git a/prospector/core/report.py b/prospector/core/report.py index 16897608b..fb9006271 100644 --- a/prospector/core/report.py +++ b/prospector/core/report.py @@ -24,12 +24,14 @@ def default(self, obj): def json_( results: List[Commit], advisory_record: AdvisoryRecord, + params, filename: str = "prospector-report.json", no_diff: bool = False, ): fn = filename if filename.endswith(".json") else f"{filename}.json" data = { + "parameters": params, "advisory_record": advisory_record.__dict__, "commits": [ r.as_dict(no_hash=True, no_rules=False, no_diff=no_diff) for r in results @@ -106,18 +108,35 @@ def format_annotations(commit: Commit) -> str: def generate_report( - results, advisory_record, report_type, report_filename, report_diff=False + results, + advisory_record, + report_type, + report_filename, + prospector_params, + report_diff=False, ): with ConsoleWriter("Generating report\n") as console: match report_type: case "console": console_(results, advisory_record, get_level() < logging.INFO) case "json": - json_(results, advisory_record, report_filename, report_diff) + json_( + results, + advisory_record, + prospector_params, + report_filename, + report_diff, + ) case "html": html_(results, advisory_record, report_filename) case "all": - json_(results, advisory_record, report_filename, report_diff) + json_( + results, + advisory_record, + prospector_params, + report_filename, + report_diff, + ) html_(results, advisory_record, report_filename) case _: logger.warning("Invalid report type specified, using 'console'") diff --git a/prospector/util/config_parser.py b/prospector/util/config_parser.py index b5391d1ca..593bd676a 100644 --- a/prospector/util/config_parser.py +++ b/prospector/util/config_parser.py @@ -84,6 +84,12 @@ def parse_cli_args(args): help="Get data from NVD", ) + parser.add_argument( + "--no-diff", + action="store_true", + help="Do not include diff field in JSON report", + ) + parser.add_argument( "--fetch-references", action="store_true",