Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new reporter: MARKDOWN_SUMMARY Reporter (#3250)
* Add support of summary report * Make summary reporter disabled by default * change summary report type to md * Add documentation * Incorporated PR comments * Updated docs: Changed SUMMARY Reporter to MARKDOWN_SUMMARY Reporter * doc fix
- Loading branch information
1 parent
23193c5
commit 40eb95c
Showing
9 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: Markdown Summary Reporter for MegaLinter | ||
description: Generates a summary of SAST results in Markdown within a file named 'megalinter-report.md', located in the report folder. | ||
--- | ||
|
||
# Markdown Summary Reporter | ||
|
||
Generates a summary of SAST results in Markdown within a file named **megalinter-report.md**, located in the report folder. | ||
|
||
This reporter **is deactivated by default**. | ||
|
||
![Screenshot](../assets/images/MarkdownSummaryReporter_1.png) | ||
|
||
![Screenshot](../assets/images/MarkdownSummaryReporter_2.png) | ||
|
||
## Usage | ||
|
||
Activate the reporter (`MARKDOWN_SUMMARY_REPORTER: true`) to generate markdown summary report file. | ||
|
||
## Configuration | ||
|
||
| Variable | Description | Default value | | ||
|-----------------------------------------|-------------------------------------------------------------------------------------------------------------------|----------------------------| | ||
| MARKDOWN_SUMMARY_REPORTER | Activates/deactivates reporter | `false` | | ||
| MARKDOWN_SUMMARY_REPORTER_FILE_NAME | File name for MARKDOWN_SUMMARY report output file | `megalinter-report.md` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Produce MARKDOWN_SUMMARY report | ||
""" | ||
import logging | ||
import os | ||
|
||
from megalinter import Reporter, config, utils | ||
from megalinter.utils_reporter import build_markdown_summary | ||
from megalinter.constants import DEFAULT_MARKDOWN_SUMMARY_REPORT_FILE_NAME | ||
|
||
|
||
|
||
class MarkdownSummaryReporter(Reporter): | ||
name = "MARKDOWN_SUMMARY" | ||
scope = "mega-linter" | ||
|
||
def manage_activation(self): | ||
if not utils.can_write_report_files(self.master): | ||
self.is_active = False | ||
elif ( | ||
config.get(self.master.request_id, "MARKDOWN_SUMMARY_REPORTER", "false") | ||
== "true" | ||
): | ||
self.is_active = True | ||
else: | ||
self.is_active = False | ||
|
||
|
||
def produce_report(self): | ||
summary = build_markdown_summary(self) | ||
|
||
# Write output file | ||
summary_file_name = f"{self.report_folder}{os.path.sep}" + config.get( | ||
self.master.request_id, | ||
"MARKDOWN_SUMMARY_REPORTER_FILE_NAME", | ||
DEFAULT_MARKDOWN_SUMMARY_REPORT_FILE_NAME, | ||
) | ||
if os.path.isfile(summary_file_name): | ||
# Remove from previous run | ||
os.remove(summary_file_name) | ||
with open(summary_file_name, "w", encoding="utf-8") as sarif_file: | ||
sarif_file.write(summary) | ||
logging.info( | ||
f"[MARKDOWN_SUMMARY Reporter] Generated {self.name} report: {summary_file_name}" | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters