From b76b4b601676152d729ec40ef5acec44ed03b800 Mon Sep 17 00:00:00 2001 From: Calum Young <32770960+calumy@users.noreply.github.com> Date: Thu, 11 May 2023 15:33:15 +0100 Subject: [PATCH] List rule changes in ecosystem (#4371) * Count changes for each rule * Handle case where rule matches were found in a line * List and sort by changes * Remove detail from rule changes * Add comment about leading : * Only print rule changes if rule changes are present * Use re.search and match group * Remove dict().items() * Use match group to extract rule code --- scripts/check_ecosystem.py | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/scripts/check_ecosystem.py b/scripts/check_ecosystem.py index 1a68bb917e..acc3e5583c 100755 --- a/scripts/check_ecosystem.py +++ b/scripts/check_ecosystem.py @@ -255,6 +255,7 @@ async def main(*, ruff1: Path, ruff2: Path, projects_jsonl: Optional[Path]) -> N if total_removed == 0 and total_added == 0 and errors == 0: print("\u2705 ecosystem check detected no changes.") else: + rule_changes: dict[str, tuple[int, int]] = {} changes = f"(+{total_added}, -{total_removed}, {errors} error(s))" print(f"\u2139\ufe0f ecosystem check **detected changes**. {changes}") @@ -294,9 +295,47 @@ async def main(*, ruff1: Path, ruff2: Path, projects_jsonl: Optional[Path]) -> N print() print("

") print("") + + # Count rule changes + for line in diff_str.splitlines(): + # Find rule change for current line or construction + # + /::: + matches = re.search(r": ([A-Z]{1,3}[0-9]{3,4})", line) + + if matches is None: + # Handle case where there are no regex matches e.g. + # + "?application=AIRFLOW&authenticator=TEST_AUTH&role=TEST_ROLE&warehouse=TEST_WAREHOUSE" # noqa: E501, ERA001 + # Which was found in local testing + continue + + rule_code = matches.group(1) + + # Get current additions and removals for this rule + current_changes = rule_changes.get(rule_code, (0, 0)) + + # Check if addition or removal depending on the first character + if line[0] == "+": + current_changes = (current_changes[0] + 1, current_changes[1]) + elif line[0] == "-": + current_changes = (current_changes[0], current_changes[1] + 1) + + rule_changes[rule_code] = current_changes + else: continue + if len(rule_changes.keys()) > 0: + print(f"Rules changed: {len(rule_changes.keys())}") + print() + print("| Rule | Changes | Additions | Removals |") + print("| ---- | ------- | --------- | -------- |") + for rule, (additions, removals) in sorted( + rule_changes.items(), + key=lambda x: (x[1][0] + x[1][1]), + reverse=True, + ): + print(f"| {rule} | {additions + removals} | {additions} | {removals} |") + logger.debug(f"Finished {len(repositories)} repositories")