Skip to content

Commit

Permalink
Add test and logic for skipping empty summary table
Browse files Browse the repository at this point in the history
Signed-off-by: Zack Koppert <[email protected]>
  • Loading branch information
zkoppert committed Oct 19, 2023
1 parent 38e1563 commit 3da633e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 47 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}
96 changes: 53 additions & 43 deletions markdown_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def write_to_markdown(
num_issues_closed: Union[int, None],
labels=None,
search_query=None,
hide_label_metrics=False,
) -> None:
"""Write the issues with metrics to a markdown file.
Expand All @@ -94,6 +95,7 @@ def write_to_markdown(
num_issues_closed (int): The number of issues that were closed.
labels (List[str]): A list of the labels that are used in the issues.
search_query (str): The search query used to find the issues.
hide_label_metrics (bool): Represents whether the user has chosen to hide label metrics in the output
Returns:
None.
Expand Down Expand Up @@ -123,6 +125,7 @@ def write_to_markdown(
labels,
columns,
file,
hide_label_metrics,
)

# Write second table with individual issue/pr/discussion metrics
Expand Down Expand Up @@ -179,54 +182,61 @@ def write_overall_metrics_tables(
labels,
columns,
file,
hide_label_metrics,
):
"""Write the overall metrics tables to the markdown file."""
file.write("| Metric | Average | Median | 90th percentile |\n")
file.write("| --- | --- | --- | ---: |\n")
if "Time to first response" in columns:
if stats_time_to_first_response is not None:
file.write(
f"| Time to first response "
f"| {stats_time_to_first_response['avg']} "
f"| {stats_time_to_first_response['med']} "
f"| {stats_time_to_first_response['90p']} |\n"
)
else:
file.write("| Time to first response | None | None | None |\n")
if "Time to close" in columns:
if stats_time_to_close is not None:
file.write(
f"| Time to close "
f"| {stats_time_to_close['avg']} "
f"| {stats_time_to_close['med']} "
f"| {stats_time_to_close['90p']} |\n"
)
else:
file.write("| Time to close | None | None | None |\n")
if "Time to answer" in columns:
if stats_time_to_answer is not None:
file.write(
f"| Time to answer "
f"| {stats_time_to_answer['avg']} "
f"| {stats_time_to_answer['med']} "
f"| {stats_time_to_answer['90p']} |\n"
)
else:
file.write("| Time to answer | None | None | None |\n")
if labels and stats_time_in_labels:
for label in labels:
if (
f"Time spent in {label}" in columns
and label in stats_time_in_labels["avg"]
):
if (
"Time to first response" in columns
or "Time to close" in columns
or "Time to answer" in columns
or (hide_label_metrics is False and len(labels) > 0)
):
file.write("| Metric | Average | Median | 90th percentile |\n")
file.write("| --- | --- | --- | ---: |\n")
if "Time to first response" in columns:
if stats_time_to_first_response is not None:
file.write(
f"| Time to first response "
f"| {stats_time_to_first_response['avg']} "
f"| {stats_time_to_first_response['med']} "
f"| {stats_time_to_first_response['90p']} |\n"
)
else:
file.write("| Time to first response | None | None | None |\n")
if "Time to close" in columns:
if stats_time_to_close is not None:
file.write(
f"| Time spent in {label} "
f"| {stats_time_in_labels['avg'][label]} "
f"| {stats_time_in_labels['med'][label]} "
f"| {stats_time_in_labels['90p'][label]} |\n"
f"| Time to close "
f"| {stats_time_to_close['avg']} "
f"| {stats_time_to_close['med']} "
f"| {stats_time_to_close['90p']} |\n"
)
else:
file.write("| Time to close | None | None | None |\n")
if "Time to answer" in columns:
if stats_time_to_answer is not None:
file.write(
f"| Time to answer "
f"| {stats_time_to_answer['avg']} "
f"| {stats_time_to_answer['med']} "
f"| {stats_time_to_answer['90p']} |\n"
)
else:
file.write("| Time to answer | None | None | None |\n")
if labels and stats_time_in_labels:
for label in labels:
if (
f"Time spent in {label}" in columns
and label in stats_time_in_labels["avg"]
):
file.write(
f"| Time spent in {label} "
f"| {stats_time_in_labels['avg'][label]} "
f"| {stats_time_in_labels['med'][label]} "
f"| {stats_time_in_labels['90p'][label]} |\n"
)
file.write("\n")
# Write count stats to a separate table
file.write("\n")
file.write("| Metric | Count |\n")
file.write("| --- | ---: |\n")
file.write(f"| Number of items that remain open | {num_issues_opened} |\n")
Expand Down
4 changes: 1 addition & 3 deletions test_markdown_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,14 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
num_issues_closed=num_issues_closed,
labels=["label1"],
search_query="repo:user/repo is:issue",
hide_label_metrics=True,
)

# Check that the function writes the correct markdown file
with open("issue_metrics.md", "r", encoding="utf-8") as file:
content = file.read()
expected_content = (
"# Issue Metrics\n\n"
"| Metric | Average | Median | 90th percentile |\n"
"| --- | --- | --- | ---: |\n"
"\n"
"| Metric | Count |\n"
"| --- | ---: |\n"
"| Number of items that remain open | 2 |\n"
Expand Down

0 comments on commit 3da633e

Please sign in to comment.