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
14 changes: 13 additions & 1 deletion pythonbridge/core/review.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import json
import logging

from pygments.lexers import get_lexer_for_filename
from pygments.util import ClassNotFound

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
Expand All @@ -21,6 +24,13 @@ def _severity_emoji(severity: str) -> str:
return _SEVERITY_EMOJI.get(severity.lower(), "")


def _detect_language(filename: str) -> str:
try:
return get_lexer_for_filename(filename).name
except ClassNotFound:
return "Unknown"


def _build_pr_context(title: str, body: str) -> str:
return f"\n\n## PR Context\n\n**Title:** {title}\n\n**Description:**\n{body or '_No description provided._'}\n"

Expand Down Expand Up @@ -68,8 +78,10 @@ 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}"

result = agent_graph.invoke({"pr_input": annotated_patch})
result = agent_graph.invoke({"pr_input": llm_input})
raw_review = result.get("pr_review") if result else None
comments = _parse_comments(raw_review, file.filename) if raw_review else []

Expand Down
1 change: 1 addition & 0 deletions pythonbridge/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies = [
"langgraph>=1.0.7",
"pydantic>=2.12.5",
"pygithub>=2.8.1",
"pygments>=2.20.0",
"python-dotenv>=1.0.0",
"tree-sitter>=0.25.2",
"tree-sitter-python>=0.25.0",
Expand Down
11 changes: 11 additions & 0 deletions pythonbridge/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading