mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-03 12:20:38 +08:00
feat: Enhance link generation for relevant lines and refactor code in git providers and PR description tools
This commit is contained in:
@ -229,6 +229,9 @@ class BitbucketProvider(GitProvider):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
def get_line_link(self, relevant_file: str, relevant_line_start: int, relevant_line_end: int = None) -> str:
|
def get_line_link(self, relevant_file: str, relevant_line_start: int, relevant_line_end: int = None) -> str:
|
||||||
|
if relevant_line_start == -1:
|
||||||
|
link = f"{self.pr_url}/#L{relevant_file}"
|
||||||
|
else:
|
||||||
link = f"{self.pr_url}/#L{relevant_file}T{relevant_line_start}"
|
link = f"{self.pr_url}/#L{relevant_file}T{relevant_line_start}"
|
||||||
return link
|
return link
|
||||||
|
|
||||||
|
@ -506,7 +506,9 @@ class GithubProvider(GitProvider):
|
|||||||
|
|
||||||
def get_line_link(self, relevant_file: str, relevant_line_start: int, relevant_line_end: int = None) -> str:
|
def get_line_link(self, relevant_file: str, relevant_line_start: int, relevant_line_end: int = None) -> str:
|
||||||
sha_file = hashlib.sha256(relevant_file.encode('utf-8')).hexdigest()
|
sha_file = hashlib.sha256(relevant_file.encode('utf-8')).hexdigest()
|
||||||
if relevant_line_end:
|
if relevant_line_start == -1:
|
||||||
|
link = f"https://github.com/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}"
|
||||||
|
elif relevant_line_end:
|
||||||
link = f"https://github.com/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}R{relevant_line_start}-R{relevant_line_end}"
|
link = f"https://github.com/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}R{relevant_line_start}-R{relevant_line_end}"
|
||||||
else:
|
else:
|
||||||
link = f"https://github.com/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}R{relevant_line_start}"
|
link = f"https://github.com/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}R{relevant_line_start}"
|
||||||
|
@ -424,7 +424,9 @@ class GitLabProvider(GitProvider):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
def get_line_link(self, relevant_file: str, relevant_line_start: int, relevant_line_end: int = None) -> str:
|
def get_line_link(self, relevant_file: str, relevant_line_start: int, relevant_line_end: int = None) -> str:
|
||||||
if relevant_line_end:
|
if relevant_line_start == -1:
|
||||||
|
link = f"https://gitlab.com/codiumai/pr-agent/-/blob/{self.mr.source_branch}/{relevant_file}?ref_type=heads"
|
||||||
|
elif relevant_line_end:
|
||||||
link = f"https://gitlab.com/codiumai/pr-agent/-/blob/{self.mr.source_branch}/{relevant_file}?ref_type=heads#L{relevant_line_start}-L{relevant_line_end}"
|
link = f"https://gitlab.com/codiumai/pr-agent/-/blob/{self.mr.source_branch}/{relevant_file}?ref_type=heads#L{relevant_line_start}-L{relevant_line_end}"
|
||||||
else:
|
else:
|
||||||
link = f"https://gitlab.com/codiumai/pr-agent/-/blob/{self.mr.source_branch}/{relevant_file}?ref_type=heads#L{relevant_line_start}"
|
link = f"https://gitlab.com/codiumai/pr-agent/-/blob/{self.mr.source_branch}/{relevant_file}?ref_type=heads#L{relevant_line_start}"
|
||||||
|
@ -38,9 +38,9 @@ class FileWalkthrough(BaseModel):
|
|||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
{%- if enable_semantic_files_types %}
|
{%- if enable_semantic_files_types %}
|
||||||
class SemanticLabelFiles(BaseModel):
|
class SemanticLabel(BaseModel):
|
||||||
label: PRType = Field(description="A label that represent a type of semantic code changes. Use the label value, not the name")
|
label: Any(PRType, str) = Field(description="a semantic label that represents a type of code changes that occurred in the PR. You can use a label from the $PRType enum, or use additional custom labels that you define.")
|
||||||
files: List[str] = Field(description="a list of files that are relevant to the label. A file may appear in multiple labels")
|
files: List[str] = Field(description="a list of file names related to the semantic label. A file may appear in multiple labels. Present the file full path, and nothing else.")
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
Class PRDescription(BaseModel):
|
Class PRDescription(BaseModel):
|
||||||
@ -54,7 +54,7 @@ Class PRDescription(BaseModel):
|
|||||||
main_files_walkthrough: List[FileWalkthrough] = Field(max_items=10)
|
main_files_walkthrough: List[FileWalkthrough] = Field(max_items=10)
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- if enable_semantic_files_types %}
|
{%- if enable_semantic_files_types %}
|
||||||
pr_files_labels[SemanticLabelFiles]
|
pr_files_labels[List[SemanticLabel]] = Field(min_items=3, description="A list of semantic labels that describe the type of changes in the PR files.")
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
=====
|
=====
|
||||||
|
|
||||||
|
@ -275,8 +275,7 @@ class PRDescription:
|
|||||||
pr_body +="</details>\n"
|
pr_body +="</details>\n"
|
||||||
elif 'pr_files_labels' in key.lower():
|
elif 'pr_files_labels' in key.lower():
|
||||||
pr_body += """\n| | Relevant Files """
|
pr_body += """\n| | Relevant Files """
|
||||||
for i in range(60):
|
pr_body += " " * 60
|
||||||
pr_body += " "
|
|
||||||
pr_body += """|\n|-----------|-------------|\n"""
|
pr_body += """|\n|-----------|-------------|\n"""
|
||||||
for semantic_label in value:
|
for semantic_label in value:
|
||||||
# for filename, description in value.items():
|
# for filename, description in value.items():
|
||||||
@ -288,6 +287,12 @@ class PRDescription:
|
|||||||
filename = file.replace("'", "`")
|
filename = file.replace("'", "`")
|
||||||
# description = file['changes_in_file']
|
# description = file['changes_in_file']
|
||||||
# pr_body += f'- `{filename}`\n'
|
# pr_body += f'- `{filename}`\n'
|
||||||
|
|
||||||
|
# try to add line numbers link to code suggestions
|
||||||
|
if hasattr(self.git_provider, 'get_line_link'):
|
||||||
|
link = self.git_provider.get_line_link(filename, relevant_line_start=-1)
|
||||||
|
if link:
|
||||||
|
filename = f"[{filename}]({link})"
|
||||||
if self.git_provider.is_supported("gfm_markdown"):
|
if self.git_provider.is_supported("gfm_markdown"):
|
||||||
pr_body += f"<li>{filename}</li>"
|
pr_body += f"<li>{filename}</li>"
|
||||||
else:
|
else:
|
||||||
@ -296,7 +301,7 @@ class PRDescription:
|
|||||||
pr_body += "</ul></details>|\n"
|
pr_body += "</ul></details>|\n"
|
||||||
else:
|
else:
|
||||||
# if the value is a list, join its items by comma
|
# if the value is a list, join its items by comma
|
||||||
if type(value) == list:
|
if isinstance(value, list):
|
||||||
value = ', '.join(v for v in value)
|
value = ', '.join(v for v in value)
|
||||||
pr_body += f"{value}\n"
|
pr_body += f"{value}\n"
|
||||||
if idx < len(self.data) - 1:
|
if idx < len(self.data) - 1:
|
||||||
|
Reference in New Issue
Block a user