From 46fcd19ca64b99365240246caf86810fc37ba42a Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Sun, 19 May 2024 10:08:10 -0400 Subject: [PATCH] Fix division by zero error in ecosystem check (#11469) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit e.g. https://github.com/astral-sh/ruff/actions/runs/9144809516/job/25143076896?pr=11468 Screenshot 2024-05-19 at 12 02 15 AM --- python/ruff-ecosystem/ruff_ecosystem/check.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/python/ruff-ecosystem/ruff_ecosystem/check.py b/python/ruff-ecosystem/ruff_ecosystem/check.py index bebbe97a62953..680b5f204d3c8 100644 --- a/python/ruff-ecosystem/ruff_ecosystem/check.py +++ b/python/ruff-ecosystem/ruff_ecosystem/check.py @@ -145,7 +145,20 @@ def markdown_check_result(result: Result) -> str: # Limit the number of items displayed per project to between 10 and 50 # based on the proportion of total changes present in this project - max_display_per_project = max(10, int((project_changes / total_changes) * 50)) + max_display_per_project = max( + 10, + int( + ( + # TODO(zanieb): We take the `max` here to avoid division by zero errors where + # `total_changes` is zero but `total_affected_rules` is non-zero so we did not + # skip display. This shouldn't really happen and indicates a problem in the + # calculation of these values. Instead of skipping entirely when `total_changes` + # is zero, we'll attempt to report the results to help diagnose the problem. + project_changes / max(total_changes, 1) + ) + * 50 + ), + ) # Limit the number of items displayed per rule to between 5 and the max for # the project based on the number of rules affected (less rules, more per rule)