-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hl/ask line #661
Hl/ask line #661
Changes from 8 commits
fff52e9
8ed98c8
24dd57e
cfe7949
6712c0a
3eef0a4
40fbd55
c98e736
5918943
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,3 +245,59 @@ def convert_to_hunks_with_lines_numbers(patch: str, file) -> str: | |
patch_with_lines_str += f"{line_old}\n" | ||
|
||
return patch_with_lines_str.rstrip() | ||
|
||
|
||
def extract_hunk_lines_from_patch(patch: str, file_name, line_start, line_end, side) -> tuple[str, str]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. תהיה בנאדם, תוסיף דוקסטרינג קצר. אח״כ רוצים להשתמש בזה שוב, וצריכים לנחש מה הפונקציה עושה |
||
|
||
patch_with_lines_str = f"\n\n## file: '{file_name.strip()}'\n\n" | ||
selected_lines = "" | ||
patch_lines = patch.splitlines() | ||
RE_HUNK_HEADER = re.compile( | ||
r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@[ ]?(.*)") | ||
match = None | ||
start1, size1, start2, size2 = -1, -1, -1, -1 | ||
skip_hunk = False | ||
selected_lines_num = 0 | ||
for line in patch_lines: | ||
if 'no newline at end of file' in line.lower(): | ||
continue | ||
|
||
if line.startswith('@@'): | ||
skip_hunk = False | ||
selected_lines_num = 0 | ||
header_line = line | ||
|
||
match = RE_HUNK_HEADER.match(line) | ||
|
||
res = list(match.groups()) | ||
for i in range(len(res)): | ||
if res[i] is None: | ||
res[i] = 0 | ||
try: | ||
start1, size1, start2, size2 = map(int, res[:4]) | ||
except: # '@@ -0,0 +1 @@' case | ||
start1, size1, size2 = map(int, res[:3]) | ||
start2 = 0 | ||
|
||
# check if line range is in this hunk | ||
if side.lower() == 'left': | ||
# check if line range is in this hunk | ||
if not (start1 <= line_start <= start1 + size1): | ||
skip_hunk = True | ||
continue | ||
elif side.lower() == 'right': | ||
if not (start2 <= line_start <= start2 + size2): | ||
skip_hunk = True | ||
continue | ||
patch_with_lines_str += f'\n{header_line}\n' | ||
|
||
elif not skip_hunk: | ||
if side.lower() == 'right' and line_start <= start2 + selected_lines_num <= line_end: | ||
selected_lines += line + '\n' | ||
if side.lower() == 'left' and start1 <= selected_lines_num + start1 <= line_end: | ||
selected_lines += line + '\n' | ||
patch_with_lines_str += line + '\n' | ||
if not line.startswith('-'): # currently we don't support /ask line for deleted lines | ||
selected_lines_num += 1 | ||
|
||
return patch_with_lines_str.rstrip(), selected_lines.rstrip() |
mrT23 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,25 @@ async def gitlab_webhook(background_tasks: BackgroundTasks, request: Request): | |
mr = data['merge_request'] | ||
url = mr.get('url') | ||
body = data.get('object_attributes', {}).get('note') | ||
if data.get('object_attributes', {}).get('type') == 'DiffNote' and '/ask' in body: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this to a dedicated function |
||
line_range_ = data['object_attributes']['position']['line_range'] | ||
|
||
# if line_range_['start']['type'] == 'new': | ||
start_line = line_range_['start']['new_line'] | ||
end_line = line_range_['end']['new_line'] | ||
# else: | ||
# start_line = line_range_['start']['old_line'] | ||
# end_line = line_range_['end']['old_line'] | ||
|
||
question = body.replace('/ask', '').strip() | ||
path = data['object_attributes']['position']['new_path'] | ||
side = 'RIGHT'# if line_range_['start']['type'] == 'new' else 'LEFT' | ||
comment_id = data['object_attributes']["discussion_id"] | ||
get_logger().info(f"Handling line comment") | ||
body = f"/ask_line --line_start={start_line} --line_end={end_line} --side={side} --file_name={path} --comment_id={comment_id} {question}" | ||
|
||
handle_request(background_tasks, url, body, log_context) | ||
|
||
return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes walkthrough
pr_agent.py (+2/-0)
Integrate Line-Specific Question
Handling in PR Agent
git_patch_processing.py (+54/-0)
Add Function to Extract Specific Lines
from Patches
git_provider.py (+3/-0)
Define Method for Replying to Comments
by ID in Git Provider Interface
github_provider.py (+17/-0)
Implement Comment Reply and Reaction
Features for GitHub Provider
github_app.py (+20/-0)
Add Handling for Line Comments in GitHub
App
pr_line_questions.py (+105/-0)
Implement Line-Specific Question
Handling
config_loader.py (+1/-0)
Update Configuration Loader to Include
Line Questions Prompts
pr_line_questions_prompts.toml (+53/-0)
Add Prompts Configuration for
Line-Specific Questions
ASK.md (+9/-0)
Document Line-Specific Questions Feature