Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove plan from report if comment is too long #35

Merged
merged 16 commits into from
May 21, 2024
Merged
37 changes: 26 additions & 11 deletions tfcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ def check(path: str, plan_args: Optional[str] = None) -> CheckResult:
)


def remove_plan(report: str) -> str:
report_lines = []
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()

Expand All @@ -157,17 +170,19 @@ def check(path: str, plan_args: Optional[str] = None) -> CheckResult:
)

if args.report:
args.report.write(
template.render(
path=result.path,
init_result=result.init_result(),
check_result=result.check_result_msg(),
fmt_result=result.fmt_result(),
validate_result=result.validate_result(),
plan_result=result.plan_result(),
plan_output=result.plan_output,
plan_msg=result.plan_msg(),
)
report = template.render(
path=result.path,
init_result=result.init_result(),
check_result=result.check_result_msg(),
fmt_result=result.fmt_result(),
validate_result=result.validate_result(),
plan_result=result.plan_result(),
plan_output=result.plan_output,
plan_msg=result.plan_msg(),
)
if len(report) > 65536:
report = remove_plan(report)

args.report.write(report)

sys.exit(result.exitcode())