LukeMattingly
commited on
Commit
·
650b8c5
1
Parent(s):
c7c05dd
enhance the get_pr_diff functionality to allow more context
Browse files
app.py
CHANGED
@@ -59,16 +59,21 @@ def find_todo_comments(code: str) -> str:
|
|
59 |
return "\n".join([f"{match[0]}: {match[1]}" for match in matches])
|
60 |
|
61 |
@tool
|
62 |
-
def get_pr_diff(github_url: str, pr_number: int) -> str:
|
63 |
-
"""Fetches the code diff of a specific pull request.
|
64 |
|
65 |
Args:
|
66 |
github_url: The URL of the GitHub repository where the pull request is located.
|
|
|
67 |
pr_number: The pull request number for which the code diff should be retrieved.
|
|
|
|
|
|
|
|
|
68 |
|
69 |
Returns:
|
70 |
-
A string containing the code diff of the specified pull request.
|
71 |
-
If the diff cannot be retrieved, returns an error message.
|
72 |
"""
|
73 |
try:
|
74 |
owner_repo = github_url.replace("https://github.com/", "")
|
@@ -78,8 +83,20 @@ def get_pr_diff(github_url: str, pr_number: int) -> str:
|
|
78 |
if response.status_code != 200:
|
79 |
return f"Error fetching PR diff: {response.json().get('message', 'Unknown error')}"
|
80 |
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
except Exception as e:
|
84 |
return f"Error retrieving PR diff: {str(e)}"
|
85 |
|
|
|
59 |
return "\n".join([f"{match[0]}: {match[1]}" for match in matches])
|
60 |
|
61 |
@tool
|
62 |
+
def get_pr_diff(github_url: str, pr_number: int, start_line: int = None, end_line: int = None, total_lines: int = None) -> str:
|
63 |
+
"""Fetches the code diff of a specific pull request and returns a subset of lines as requested.
|
64 |
|
65 |
Args:
|
66 |
github_url: The URL of the GitHub repository where the pull request is located.
|
67 |
+
(e.g., 'https://github.com/crewAIInc/crewAI').
|
68 |
pr_number: The pull request number for which the code diff should be retrieved.
|
69 |
+
start_line: Optional; the starting line number (1-indexed) of the diff to return.
|
70 |
+
end_line: Optional; the ending line number (1-indexed) of the diff to return.
|
71 |
+
total_lines: Optional; if provided, returns the first 'total_lines' lines of the diff.
|
72 |
+
This parameter is ignored if both start_line and end_line are provided.
|
73 |
|
74 |
Returns:
|
75 |
+
A string containing the requested portion of the code diff of the specified pull request.
|
76 |
+
If the diff cannot be retrieved or if invalid parameters are provided, returns an error message.
|
77 |
"""
|
78 |
try:
|
79 |
owner_repo = github_url.replace("https://github.com/", "")
|
|
|
83 |
if response.status_code != 200:
|
84 |
return f"Error fetching PR diff: {response.json().get('message', 'Unknown error')}"
|
85 |
|
86 |
+
diff_text = response.text
|
87 |
+
# Split the diff into individual lines
|
88 |
+
diff_lines = diff_text.splitlines()
|
89 |
+
|
90 |
+
# Determine which subset of lines to return:
|
91 |
+
if start_line is not None or end_line is not None:
|
92 |
+
if start_line is None or end_line is None:
|
93 |
+
return "Error: Both start_line and end_line must be provided if specifying a range."
|
94 |
+
# Adjust for 1-indexed line numbers provided by the user.
|
95 |
+
diff_lines = diff_lines[start_line - 1:end_line]
|
96 |
+
elif total_lines is not None:
|
97 |
+
diff_lines = diff_lines[:total_lines]
|
98 |
+
|
99 |
+
return "\n".join(diff_lines)
|
100 |
except Exception as e:
|
101 |
return f"Error retrieving PR diff: {str(e)}"
|
102 |
|