Skip to content

Commit 6162636

Browse files
authored
Merge pull request #11 from per1234/restrict-report-length
Prevent report from exceeding maximum comment length
2 parents 495ca5e + e92ac11 commit 6162636

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

reportsizedeltas/reportsizedeltas.py

+26-15
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ def generate_report(self, sketches_reports):
316316
Keyword arguments:
317317
sketches_reports -- list of sketches_reports containing the data to generate the deltas report from
318318
"""
319+
# From https://github.community/t/maximum-length-for-the-comment-body-in-issues-and-pr/148867/2
320+
# > PR body/Issue comments are still stored in MySQL as a mediumblob with a maximum value length of 262,144.
321+
# > This equals a limit of 65,536 4-byte unicode characters.
322+
maximum_report_length = 262144
323+
319324
fqbn_column_heading = "Board"
320325

321326
# Generate summary report data
@@ -395,21 +400,27 @@ def generate_report(self, sketches_reports):
395400
report_markdown = report_markdown + generate_markdown_table(row_list=summary_report_data) + "\n"
396401

397402
# Add full table
398-
report_markdown = (report_markdown
399-
+ "<details>\n"
400-
"<summary>Click for full report table</summary>\n\n")
401-
report_markdown = (report_markdown
402-
+ generate_markdown_table(row_list=full_report_data)
403-
+ "\n</details>\n\n")
404-
405-
# Add full CSV
406-
report_markdown = (report_markdown
407-
+ "<details>\n"
408-
"<summary>Click for full report CSV</summary>\n\n"
409-
"```\n")
410-
report_markdown = (report_markdown
411-
+ generate_csv_table(row_list=full_report_data)
412-
+ "```\n</details>")
403+
report_markdown_with_table = (report_markdown
404+
+ "<details>\n"
405+
"<summary>Click for full report table</summary>\n\n")
406+
report_markdown_with_table = (report_markdown_with_table
407+
+ generate_markdown_table(row_list=full_report_data)
408+
+ "\n</details>\n\n")
409+
410+
if len(report_markdown_with_table) < maximum_report_length:
411+
report_markdown = report_markdown_with_table
412+
413+
# Add full CSV
414+
report_markdown_with_csv = (report_markdown
415+
+ "<details>\n"
416+
"<summary>Click for full report CSV</summary>\n\n"
417+
"```\n")
418+
report_markdown_with_csv = (report_markdown_with_csv
419+
+ generate_csv_table(row_list=full_report_data)
420+
+ "```\n</details>")
421+
422+
if len(report_markdown_with_csv) < maximum_report_length:
423+
report_markdown = report_markdown_with_csv
413424

414425
logger.debug("Report:\n" + report_markdown)
415426
return report_markdown

0 commit comments

Comments
 (0)