Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 43 additions & 17 deletions format_issue_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,17 @@ def format_summary(report):


def format_report(summaries, py_version):
template = textwrap.dedent("""\
template = textwrap.dedent(
"""\
<details><summary>Python {py_version} Test Summary</summary>

```
{summaries}
```

</details>
""")
""",
)
# 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
Expand Down Expand Up @@ -238,20 +240,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)
Expand All @@ -268,8 +257,45 @@ 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 = path.read_text().splitlines()
except FileNotFoundError:
message = textwrap.dedent(
f"""\
Something went wrong.

However, the log file at

```
{path}
```

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])
body = "\n".join([workflow_link, "", message])

output_file = args["issue-body"]
print(f"Writing output file to: {output_file.absolute()}")
Expand Down