-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove plan from report if comment is too long (#35)
* Remove plan if report is too long * Keep full report for job summary * Set report as full report by default * Naming * Fix logic * Missed -full-report arg * Remove plans from the overall report file * Fix script call * Add instruction to check the full report * Italicize comment * Update report_postprocess.py * Update report_postprocess.py * Update report_postprocess.py * Update report_postprocess.py * Update report_postprocess.py * Update report_postprocess.py
- Loading branch information
1 parent
e4c9ae5
commit 1b6d220
Showing
2 changed files
with
44 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import argparse | ||
import os | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"report", | ||
help="Path to report file in markdown format", | ||
type=argparse.FileType("r+", encoding="UTF-8"), | ||
) | ||
|
||
|
||
def remove_plan(report: str) -> str: | ||
report_lines = [ | ||
f"### ⚠️ _Terraform plan details have been removed from the report to fit within the maximum comment length. Check [workflow summary]({os.environ["GITHUB_SERVER_URL"]}/{os.environ["GITHUB_REPOSITORY"]}/actions/runs/{os.environ["GITHUB_RUN_ID"]}) for the full report._", | ||
"", | ||
"---", | ||
"" | ||
] | ||
add_line = True | ||
for line in report.splitlines(): | ||
if add_line and line == "<details><summary>Show Plan</summary>": | ||
add_line = False | ||
if add_line: | ||
report_lines.append(line) | ||
if not add_line and line == "</details>": | ||
add_line = True | ||
return "\n".join(report_lines) | ||
|
||
|
||
if __name__ == "__main__": | ||
args = parser.parse_args() | ||
|
||
report = args.report.read() | ||
if len(report) > 65536: | ||
report = remove_plan(report) | ||
|
||
args.report.seek(0) | ||
args.report.truncate() | ||
args.report.write(report) |