diff --git a/.gitignore b/.gitignore index 4964054..5893c13 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ reviews .venv .DS_Store +.history \ No newline at end of file diff --git a/main.py b/main.py index 03ac96e..1c5de2c 100644 --- a/main.py +++ b/main.py @@ -2,12 +2,12 @@ import re import os import shutil -from git import Blob, RemoteReference, Repo, GitCommandError, Tree +from git import Blob, Repo, GitCommandError, Tree import datetime repo_path = "repos" reviews_path = "reviews" -model_to_use = "qwen3-32b-mlx" #"qwen/qwen2.5-coder-32b" +model_to_use = "qwen3-53b-a3b-2507-thinking-total-recall-v2-master-coder-1m-dwq4-mlx" #"qwen/qwen3-30b-a3b" #"qwen3-32b-mlx" #"qwen/qwen2.5-coder-32b" model = lms.llm(model_to_use, config={ @@ -198,53 +198,103 @@ def main(): try: - clone_repo_to_temp() - selected_branch = list_branches() - print(f"\nAussuchen von Commits in Branch '{selected_branch}'...") - - commit_hash = select_commit(selected_branch) + print("Was soll reviewt werden?") + print("1. Git-Branche") + print("2. Ordner") + your_choice = input() + if your_choice == "1": + clone_repo_to_temp() + selected_branch = list_branches() - print(f"\nCheckout des Commits {commit_hash[:7]}...") - checkout_commit_to_temp(commit_hash) - files = get_files_in_commit(commit_hash) - start_time_commit = datetime.datetime.now() + print(f"\nAussuchen von Commits in Branch '{selected_branch}'...") - print(f"\nBeginne Code Reviews des Commits {commit_hash[:7]} ({start_time_commit})...") - print(f"\nIn diesem Commit wurden die folgenden Dateien geändert:") - for file in files: - print(f"- {file}") - recreate_dir(f"reviews/{commit_hash}") + commit_hash = select_commit(selected_branch) - gitignore_files = read_gitignore_file() + print(f"\nCheckout des Commits {commit_hash[:7]}...") + checkout_commit_to_temp(commit_hash) + files = get_files_in_commit(commit_hash) + start_time_commit = datetime.datetime.now() - for file in files: - try: - file_to_review = f"{repo_path}/{file}" - code_content = read_code_file(file_to_review, file, gitignore_files) - if code_content is None: - continue - start_time_file = datetime.datetime.now() + print(f"\nBeginne Code Reviews des Commits {commit_hash[:7]} ({start_time_commit})...") + print(f"\nIn diesem Commit wurden die folgenden Dateien geändert:") + for file in files: + print(f"- {file}") + recreate_dir(f"reviews/{commit_hash}") + + gitignore_files = read_gitignore_file() - print(f"\nReviewe Datei {file} ({start_time_file})...") + for file in files: + try: + file_to_review = f"{repo_path}/{file}" + code_content = read_code_file(file_to_review, file, gitignore_files) + if code_content is None: + continue + start_time_file = datetime.datetime.now() - review_result = get_llm_response(code_content) - write_html_file(review_result, commit_hash, file) - end_time_file = datetime.datetime.now() - file_review_duration = calc_time_duration(start_time_file, end_time_file) + print(f"\nReviewe Datei {file} ({start_time_file})...") - print(f"\nReview der Datei {file} abgeschlossen ({end_time_file}). Dauer: {file_review_duration}") - except Exception as e: - print(f"Fehler beim Lesen der Datei: {e}") - end_time_commit = datetime.datetime.now() - commit_duration = calc_time_duration(start_time_commit, end_time_commit) + review_result = get_llm_response(code_content) + write_html_file(review_result, commit_hash, file) + end_time_file = datetime.datetime.now() + file_review_duration = calc_time_duration(start_time_file, end_time_file) - print(f"\nAbschluss Code Review des Commits {commit_hash[:7]} ({end_time_commit}). Dauer: {commit_duration}") + print(f"\nReview der Datei {file} abgeschlossen ({end_time_file}). Dauer: {file_review_duration}") + except Exception as e: + print(f"Fehler beim Lesen der Datei: {e}") + end_time_commit = datetime.datetime.now() + commit_duration = calc_time_duration(start_time_commit, end_time_commit) - delete_temp_branches() + print(f"\nAbschluss Code Review des Commits {commit_hash[:7]} ({end_time_commit}). Dauer: {commit_duration}") - if os.path.isdir(repo_path): - shutil.rmtree(repo_path) + delete_temp_branches() + + if os.path.isdir(repo_path): + shutil.rmtree(repo_path) + elif your_choice == "2": + directory = input("Bitte gebe den zu reviewenden Ordner an.") + start_time_commit = datetime.datetime.now() + + print(f"\nBeginne Code Reviews des Ordners {directory} ({start_time_commit})...") + folder_name = os.path.basename(directory) + recreate_dir(f"reviews/{folder_name}") + + gitignore_files = read_gitignore_file() + files = [] + for root, dirs, filenames in os.walk(directory): + for filename in filenames: + file_path = os.path.join(root, filename) + + rel_path = os.path.relpath(file_path, directory) + files.append(rel_path) + + print(f"\nIn diesem Ordner werden die folgenden Dateien reviewt:") + for file in files: + print(f"- {file}") + + for file in files: + try: + file_to_review = f"{directory}/{file}" + code_content = read_code_file(file_to_review, file, gitignore_files) + if code_content is None: + continue + start_time_file = datetime.datetime.now() + + print(f"\nReviewe Datei {file} ({start_time_file})...") + + review_result = get_llm_response(code_content) + write_html_file(review_result, directory, file) + end_time_file = datetime.datetime.now() + file_review_duration = calc_time_duration(start_time_file, end_time_file) + + print(f"\nReview der Datei {file} abgeschlossen ({end_time_file}). Dauer: {file_review_duration}") + except Exception as e: + print(f"Fehler beim Lesen der Datei: {e}") + end_time_commit = datetime.datetime.now() + commit_duration = calc_time_duration(start_time_commit, end_time_commit) + + print(f"\nAbschluss Code Review des Ordners {directory} ({end_time_commit}). Dauer: {commit_duration}") + except Exception as e: print(f"Fehler: {e}")