Skip to content

Commit 3659283

Browse files
author
Jet Xu
committed
Fix bug for PR Content code diff calculation logic
1 parent 0218db5 commit 3659283

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.1.8] - 2024-11-03
9+
10+
### Optimized
11+
- fix bugs for get pr content file diff calculate logic
12+
813
## [0.1.7] - 2024-10-31
914

1015
### Optimized

llama_github/data_retrieval/github_entities.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def get_repo(self):
123123
return None
124124
self.update_last_read_time()
125125
return self._repo
126-
126+
127127
def get_structure(self, path="/") -> dict:
128128
"""
129129
Retrieves the structure of the repository using a singleton design pattern.
@@ -183,6 +183,8 @@ def get_file_content(self, file_path: str, sha: Optional[str] = None) -> Optiona
183183
decoded_content = base64.b64decode(file_content.content).decode('utf-8')
184184
elif (file_content.encoding is None or file_content.encoding == 'none') and hasattr(file_content, 'download_url') and file_content.download_url:
185185
try:
186+
logger.debug(f"Downloading file {file_path} from {file_content.download_url}")
187+
# Use requests to download the file content
186188
response = requests.get(
187189
file_content.download_url,
188190
timeout=30,
@@ -526,6 +528,7 @@ def get_pr_content(self, number, pr=None, context_lines=10) -> Dict[str, Any]:
526528
pr_data["commit_stats"] = {}
527529

528530
# Process file changes
531+
comparison = None
529532
dependency_files = ['requirements.txt', 'Pipfile', 'Pipfile.lock', 'setup.py']
530533
config_files = ['.env', 'settings.py', 'config.yaml', 'config.yml', 'config.json']
531534
for file in pr_files:
@@ -552,6 +555,16 @@ def get_pr_content(self, number, pr=None, context_lines=10) -> Dict[str, Any]:
552555
custom_diff = ''
553556
else:
554557
custom_diff = DiffGenerator.generate_custom_diff(base_content, head_content, context_lines)
558+
if not custom_diff or custom_diff.strip() == '':
559+
try:
560+
#use compare API if custom diff is empty
561+
if not comparison:
562+
comparison = self.repo.compare(pr.base.sha, pr.head.sha)
563+
patches = [f.patch for f in comparison.files if f.filename == file_path]
564+
custom_diff = patches[0] if patches else None
565+
except Exception as e:
566+
logger.exception(f"Error fetching file diff for PR #{number}")
567+
custom_diff = ''
555568

556569
# Categorize code changes
557570
change_categories = CodeAnalyzer.categorize_change(custom_diff)

llama_github/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.1.7'
1+
__version__ = '0.1.8'

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = llama-github
3-
version = 0.1.7
3+
version = 0.1.8
44
author = Jet Xu
55
author_email = [email protected]
66
description = Llama-github is an open-source Python library that empowers LLM Chatbots, AI Agents, and Auto-dev Agents to conduct Retrieval from actively selected GitHub public projects. It Augments through LLMs and Generates context for any coding question, in order to streamline the development of sophisticated AI-driven applications.

0 commit comments

Comments
 (0)