From 7428503364ef0f032177e1b5da542eb8456d4d07 Mon Sep 17 00:00:00 2001 From: Ramon Asuncion Date: Thu, 14 May 2026 16:57:45 -0400 Subject: [PATCH] feat: Add git log context per file Co-Authored-By: Claude Sonnet 4.6 --- pythonbridge/core/review.py | 6 ++++-- pythonbridge/gh/client.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pythonbridge/core/review.py b/pythonbridge/core/review.py index 211b4f9..e489c8f 100644 --- a/pythonbridge/core/review.py +++ b/pythonbridge/core/review.py @@ -6,7 +6,7 @@ from pythonbridge.core.config import load_environment from pythonbridge.core.diff_parser import parse_patch, clamp_to_valid -from pythonbridge.gh.client import get_pr, post_review, create_reaction +from pythonbridge.gh.client import get_pr, get_file_log, post_review, create_reaction from pythonbridge.llm import GraphBuilder logger = logging.getLogger(__name__) @@ -79,7 +79,9 @@ def review_pr(payload: dict) -> list[dict]: # Annotate the diff with real line numbers so the LLM can reference them accurately annotated_patch, valid_lines = parse_patch(file.patch) language = _detect_language(file.filename) - llm_input = f"Language: {language}\nFile: {file.filename}\n\n{annotated_patch}" + file_log = get_file_log(payload, file.filename) + log_str = "\n".join(f" {c['sha']} {c['author']}: {c['message']}" for c in file_log) + llm_input = f"Language: {language}\nFile: {file.filename}\nRecent commits:\n{log_str}\n\n{annotated_patch}" result = agent_graph.invoke({"pr_input": llm_input}) raw_review = result.get("pr_review") if result else None diff --git a/pythonbridge/gh/client.py b/pythonbridge/gh/client.py index ba87f39..f4fccde 100644 --- a/pythonbridge/gh/client.py +++ b/pythonbridge/gh/client.py @@ -42,6 +42,20 @@ def get_pr(payload: dict) -> tuple: return pr.get_files(), pr.title, pr.body or "", pr.head.sha +def get_file_log(payload: dict, filename: str, limit: int = 5) -> list[dict]: + """Get recent commit history for a file.""" + repo = _get_repo(payload) + commits = repo.get_commits(path=filename) + return [ + { + "sha": c.sha[:7], + "message": c.commit.message.splitlines()[0], + "author": c.commit.author.name, + } + for c in list(commits[:limit]) + ] + + def post_review(payload: dict, comments: list[dict], head_sha: str) -> None: """Post inline review comments to a pull request.