From eb05d6a99cd1182e84c20523d1c3081972cad15c Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Sat, 27 Jun 2026 15:07:07 +0200 Subject: [PATCH 1/6] make the formatter handle a missing log file --- format_issue_body.py | 46 ++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/format_issue_body.py b/format_issue_body.py index c825853..66c4d8a 100644 --- a/format_issue_body.py +++ b/format_issue_body.py @@ -238,20 +238,7 @@ def format_collection_error(error, **formatter_kwargs): """).format(py_version=py_version, name=error.name, traceback=error.repr_) -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument("log-file", type=pathlib.Path) - parser.add_argument("workflow-url", type=str) - parser.add_argument( - "issue-body", type=pathlib.Path, default="issue-body.md", nargs="?" - ) - args = vars(parser.parse_args()) - - py_version = ".".join(str(_) for _ in sys.version_info[:2]) - - print("Parsing logs ...") - - lines = args["log-file"].read_text().splitlines() +def format_message(lines): parsed_lines = [json.loads(line) for line in lines] reports = [ parse_record(data) @@ -268,6 +255,37 @@ def format_collection_error(error, **formatter_kwargs): preformatted, max_chars=65535, py_version=py_version ) + return message + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("log-file", type=pathlib.Path) + parser.add_argument("workflow-url", type=str) + parser.add_argument( + "issue-body", type=pathlib.Path, default="issue-body.md", nargs="?" + ) + args = vars(parser.parse_args()) + + py_version = ".".join(str(_) for _ in sys.version_info[:2]) + + print("Parsing logs ...") + + path = args["log-file"] + + try: + lines = args["log-file"].read_text().splitlines() + except FileNotFoundError: + message = textwrap.dedent( + """\ + Something went wrong. + + However, the log file does not exist so there are no additional details. + """, + ) + else: + message = format_message(lines) + workflow_link = f"[Workflow Run URL]({args['workflow-url']})" body = "\n".join([workflow_link, message]) From c9088e8b0f89854461de654e08be3dbf1e959fb0 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Sat, 27 Jun 2026 15:08:16 +0200 Subject: [PATCH 2/6] include the log path --- format_issue_body.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/format_issue_body.py b/format_issue_body.py index 66c4d8a..958f6e4 100644 --- a/format_issue_body.py +++ b/format_issue_body.py @@ -280,7 +280,13 @@ def format_message(lines): """\ Something went wrong. - However, the log file does not exist so there are no additional details. + However, the log file at + + ``` + {path} + ``` + + does not exist so there are no additional details. """, ) else: From 3e9d62deac24aea5858293bfea60ee7232192abf Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Sat, 27 Jun 2026 15:08:44 +0200 Subject: [PATCH 3/6] use the extracted path --- format_issue_body.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format_issue_body.py b/format_issue_body.py index 958f6e4..6e8a3c5 100644 --- a/format_issue_body.py +++ b/format_issue_body.py @@ -274,7 +274,7 @@ def format_message(lines): path = args["log-file"] try: - lines = args["log-file"].read_text().splitlines() + lines = path.read_text().splitlines() except FileNotFoundError: message = textwrap.dedent( """\ From e08fb140ad57430a5dfe4b960d18e6d6f415d731 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Sat, 27 Jun 2026 15:08:56 +0200 Subject: [PATCH 4/6] formatting --- format_issue_body.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/format_issue_body.py b/format_issue_body.py index 6e8a3c5..ea40d1d 100644 --- a/format_issue_body.py +++ b/format_issue_body.py @@ -149,7 +149,8 @@ def format_summary(report): def format_report(summaries, py_version): - template = textwrap.dedent("""\ + template = textwrap.dedent( + """\
Python {py_version} Test Summary ``` @@ -157,7 +158,8 @@ def format_report(summaries, py_version): ```
- """) + """, + ) # can't use f-strings because that would format *before* the dedenting message = template.format(summaries="\n".join(summaries), py_version=py_version) return message From b8c2ebb64acc82fdc94f090282a3ca73166ae066 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Sat, 27 Jun 2026 15:10:57 +0200 Subject: [PATCH 5/6] actually perform string interpolation --- format_issue_body.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format_issue_body.py b/format_issue_body.py index ea40d1d..69c2c0e 100644 --- a/format_issue_body.py +++ b/format_issue_body.py @@ -279,7 +279,7 @@ def format_message(lines): lines = path.read_text().splitlines() except FileNotFoundError: message = textwrap.dedent( - """\ + f"""\ Something went wrong. However, the log file at From 721ba0d918e95bacb513378a662e995f81983ce6 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Sat, 27 Jun 2026 15:11:11 +0200 Subject: [PATCH 6/6] add an additional empty line for better styling --- format_issue_body.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format_issue_body.py b/format_issue_body.py index 69c2c0e..ab73247 100644 --- a/format_issue_body.py +++ b/format_issue_body.py @@ -295,7 +295,7 @@ def format_message(lines): message = format_message(lines) workflow_link = f"[Workflow Run URL]({args['workflow-url']})" - body = "\n".join([workflow_link, message]) + body = "\n".join([workflow_link, "", message]) output_file = args["issue-body"] print(f"Writing output file to: {output_file.absolute()}")