mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-15 18:20:37 +08:00
Inline suggestion refactor + Gitlab WORKS
This commit is contained in:
@ -111,34 +111,14 @@ class PRReviewer:
|
||||
return markdown_text
|
||||
|
||||
def _publish_inline_code_comments(self):
|
||||
if settings.config.git_provider != 'github': # inline comments are currently only supported for github
|
||||
return
|
||||
|
||||
review = self.prediction.strip()
|
||||
try:
|
||||
data = json.loads(review)
|
||||
except json.decoder.JSONDecodeError:
|
||||
data = try_fix_json(review)
|
||||
|
||||
pr = self.git_provider.pr
|
||||
last_commit_id = list(pr.get_commits())[-1]
|
||||
files = list(self.git_provider.get_diff_files())
|
||||
|
||||
for d in data['PR Feedback']['Code suggestions']:
|
||||
relevant_file = d['relevant file'].strip()
|
||||
relevant_line_in_file = d['relevant line in file'].strip()
|
||||
content = d['suggestion content']
|
||||
position = -1
|
||||
for file in files:
|
||||
if file.filename.strip() == relevant_file:
|
||||
patch = file.patch
|
||||
patch_lines = patch.splitlines()
|
||||
for i, line in enumerate(patch_lines):
|
||||
if relevant_line_in_file in line:
|
||||
position = i
|
||||
if position == -1:
|
||||
logging.info(f"Could not find position for {relevant_file} {relevant_line_in_file}")
|
||||
else:
|
||||
body = content
|
||||
path = relevant_file.strip()
|
||||
pr.create_review_comment(body=body, commit_id=last_commit_id, path=path, position=position)
|
||||
self.git_provider.publish_inline_comment(content, relevant_file, relevant_line_in_file)
|
Reference in New Issue
Block a user