Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pythonbridge/core/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions pythonbridge/gh/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading