From 4a1fc23a61e80e943b9be07aa0eefe9d60d4229a Mon Sep 17 00:00:00 2001 From: Sourav Agrawal <146818014+sourava01@users.noreply.github.com> Date: Sun, 5 May 2024 12:50:29 +0530 Subject: [PATCH] feat(github): add summary message in github_failed_only output (#6131) * add summary message in github_output * fix failing checks and add some formating --- checkov/common/output/report.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/checkov/common/output/report.py b/checkov/common/output/report.py index b2aece61b15..1d46ec8ee4f 100644 --- a/checkov/common/output/report.py +++ b/checkov/common/output/report.py @@ -367,20 +367,30 @@ def print_failed_github_md(self, use_bc_ids: bool = False) -> str: result.append( [ record.get_output_id(use_bc_ids), - record.file_path, - record.resource, record.check_name, - record.guideline, + record.resource, + f"[Link]({record.guideline})", + record.file_path, ] ) if result: + summary = self.get_summary() + if self.parsing_errors: + message = "Passed Checks: {}, Failed Checks: {}, Skipped Checks: {}, Parsing Errors: {}\n\n".format( + summary["passed"], + summary["failed"], + summary["skipped"], + summary["parsing_errors"], + ) + else: + message = f"```\nPassed Checks: {summary['passed']}, Failed Checks: {summary['failed']}, Skipped Checks: {summary['skipped']}\n```\n\n" + table = tabulate( result, - headers=["check_id", "file", "resource", "check_name", "guideline"], + headers=["Check ID", "Check Name", "Resource", "Guideline", "File"], tablefmt="github", - showindex=True, ) - output_data = f"### {self.check_type} scan results:\n\n{table}\n\n---\n" + output_data = f"### {self.check_type.replace('_', ' ').title()} Scan Results:\n\n{message}{table}\n\n---\n" return output_data else: return "\n\n---\n\n"