From d1ce46d3fea1658e5b254b7d85538f8420fabbce Mon Sep 17 00:00:00 2001 From: h7x4 Date: Thu, 11 Sep 2025 13:08:57 +0200 Subject: [PATCH] newModuleTagger: colorize output --- newModuleTagger/find_prs.py | 45 ++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/newModuleTagger/find_prs.py b/newModuleTagger/find_prs.py index 41a5a52..564e1fe 100755 --- a/newModuleTagger/find_prs.py +++ b/newModuleTagger/find_prs.py @@ -99,13 +99,48 @@ def find_prs_without_new_module_tag(): pbar.update(PAGINATION_STEP) +STATUS_COLORS = { + 'OPEN': "\033[1;32mOPEN\033[0m", + 'MERGED': "\033[1;35mMERGED\033[0m", + 'CLOSED': "\033[1;31mCLOSED\033[0m" +} -def print_pr(pr): - tqdm.write(f'[{pr["state"]}|{pr["number"]}] {pr["author"]} - {pr["title"]}') - tqdm.write(pr["url"]) - tqdm.write(f'Files:') +CHANGE_TYPE_COLORS = { + 'ADDED': "\033[1;32mADDED\033[0m", + 'MODIFIED': "\033[1;33mMODIFIED\033[0m", + 'RENAMED': "\033[1;36mRENAMED\033[0m", + 'DELETED': "\033[1;31mDELETED\033[0m" +} + +def color_file_path(path: str, changeType: str) -> str: + if path == 'nixos/modules/module-list.nix': + return f"\033[1;31m{path}\033[0m" + elif changeType == 'ADDED' and path.startswith("nixos/modules/") and path.endswith('.nix'): + return f"\033[1;32m{path}\033[0m" + elif path == 'nixos/tests/all-tests.nix': + return f"\033[1;31m{path}\033[0m" + elif changeType == 'ADDED' and path.startswith("nixos/tests/") and path.endswith('.nix'): + return f"\033[1;34m{path}\033[0m" + elif path.endswith('.md'): + return f"\033[1;33m{path}\033[0m" + else: + return path + +def color_backport_label(title: str) -> str: + if title.startswith("[Backport release-"): + return "\033[31m" + title + "\033[0m" + else: + return title + +def print_pr(pr: dict[str, any]): + tqdm.write(f'[{STATUS_COLORS.get(pr["state"], pr["state"])}|\033[1m{pr["number"]}\033[0m] {pr["author"]} - {color_backport_label(pr["title"])}') + tqdm.write("\033[1;34m" + pr["url"] + "\033[0m") + tqdm.write("") + tqdm.write('Files:') for file in pr["files"]: - tqdm.write(f' {file}') + tqdm.write(f' [{CHANGE_TYPE_COLORS.get(file['changeType'], file['changeType'])}] {color_file_path(file['path'], file['changeType'])}') + tqdm.write("") + tqdm.write("------------------------------------------------------------------------------") tqdm.write("")