Skip to content
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

Enhancement of PR Description and Labeling Features with Semantic File Types and Line Count #509

Merged
merged 15 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pr_agent/algo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def set_custom_labels(variables):
labels = get_settings().custom_labels
if not labels:
# set default labels
labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation', 'Other']
labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Enhancement', 'Documentation', 'Other']
labels_list = "\n - ".join(labels) if labels else ""
labels_list = f" - {labels_list}" if labels_list else ""
variables["custom_labels"] = labels_list
Expand All @@ -367,7 +367,7 @@ def get_user_labels(current_labels: List[str] = None):
current_labels = []
user_labels = []
for label in current_labels:
if label.lower() in ['bug fix', 'tests', 'refactoring', 'enhancement', 'documentation', 'other']:
if label.lower() in ['bug fix', 'tests', 'enhancement', 'documentation', 'other']:
continue
if get_settings().config.enable_custom_labels:
if label in get_settings().custom_labels:
Expand Down
5 changes: 4 additions & 1 deletion pr_agent/git_providers/bitbucket_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ def publish_inline_comment(self, comment: str, from_line: int, file: str):
return response

def get_line_link(self, relevant_file: str, relevant_line_start: int, relevant_line_end: int = None) -> str:
link = f"{self.pr_url}/#L{relevant_file}T{relevant_line_start}"
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}"
return link

def generate_link_to_relevant_line_number(self, suggestion) -> str:
Expand Down
2 changes: 2 additions & 0 deletions pr_agent/git_providers/git_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class FilePatchInfo:
tokens: int = -1
edit_type: EDIT_TYPE = EDIT_TYPE.UNKNOWN
old_filename: str = None
num_plus_lines: int = -1
num_minus_lines: int = -1


class GitProvider(ABC):
Expand Down
15 changes: 12 additions & 3 deletions pr_agent/git_providers/github_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,15 @@ def get_diff_files(self) -> list[FilePatchInfo]:
else:
get_logger().error(f"Unknown edit type: {file.status}")
edit_type = EDIT_TYPE.UNKNOWN

# count number of lines added and removed
patch_lines = patch.splitlines(keepends=True)
num_plus_lines = len([line for line in patch_lines if line.startswith('+')])
num_minus_lines = len([line for line in patch_lines if line.startswith('-')])
file_patch_canonical_structure = FilePatchInfo(original_file_content_str, new_file_content_str, patch,
file.filename, edit_type=edit_type)
file.filename, edit_type=edit_type,
num_plus_lines=num_plus_lines,
num_minus_lines=num_minus_lines,)
diff_files.append(file_patch_canonical_structure)

self.diff_files = diff_files
Expand Down Expand Up @@ -442,7 +449,7 @@ def _get_pr_file_content(self, file: FilePatchInfo, sha: str) -> str:
def publish_labels(self, pr_types):
try:
label_color_map = {"Bug fix": "1d76db", "Tests": "e99695", "Bug fix with tests": "c5def5",
"Refactoring": "bfdadc", "Enhancement": "bfd4f2", "Documentation": "d4c5f9",
"Enhancement": "bfd4f2", "Documentation": "d4c5f9",
"Other": "d1bcf9"}
post_parameters = []
for p in pr_types:
Expand Down Expand Up @@ -506,7 +513,9 @@ def generate_link_to_relevant_line_number(self, suggestion) -> 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()
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}"
else:
link = f"https://github.com/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}R{relevant_line_start}"
Expand Down
14 changes: 12 additions & 2 deletions pr_agent/git_providers/gitlab_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,20 @@ def get_diff_files(self) -> list[FilePatchInfo]:
if not patch:
patch = load_large_diff(filename, new_file_content_str, original_file_content_str)


# count number of lines added and removed
patch_lines = patch.splitlines(keepends=True)
num_plus_lines = len([line for line in patch_lines if line.startswith('+')])
num_minus_lines = len([line for line in patch_lines if line.startswith('-')])
diff_files.append(
FilePatchInfo(original_file_content_str, new_file_content_str,
patch=patch,
filename=filename,
edit_type=edit_type,
old_filename=None if diff['old_path'] == diff['new_path'] else diff['old_path']))
old_filename=None if diff['old_path'] == diff['new_path'] else diff['old_path'],
num_plus_lines=num_plus_lines,
num_minus_lines=num_minus_lines, ))

self.diff_files = diff_files
return diff_files

Expand Down Expand Up @@ -424,7 +432,9 @@ def get_pr_id(self):
return ""

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}"
else:
link = f"https://gitlab.com/codiumai/pr-agent/-/blob/{self.mr.source_branch}/{relevant_file}?ref_type=heads#L{relevant_line_start}"
Expand Down
24 changes: 12 additions & 12 deletions pr_agent/servers/help.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
commands_text = "> **/review**: Request a review of your Pull Request.\n" \
"> **/describe**: Update the PR title and description based on the contents of the PR.\n" \
"> **/improve [--extended]**: Suggest code improvements. Extended mode provides a higher quality feedback.\n" \
"> **/ask \\<QUESTION\\>**: Ask a question about the PR.\n" \
"> **/update_changelog**: Update the changelog based on the PR's contents.\n" \
"> **/add_docs**: Generate docstring for new components introduced in the PR.\n" \
"> **/generate_labels**: Generate labels for the PR based on the PR's contents.\n" \
commands_text = "> **/review**: Request a review of your Pull Request. \n" \
"> **/describe**: Update the PR title and description based on the contents of the PR. \n" \
"> **/improve [--extended]**: Suggest code improvements. Extended mode provides a higher quality feedback. \n" \
"> **/ask \\<QUESTION\\>**: Ask a question about the PR. \n" \
"> **/update_changelog**: Update the changelog based on the PR's contents. \n" \
"> **/add_docs**: Generate docstring for new components introduced in the PR. \n" \
"> **/generate_labels**: Generate labels for the PR based on the PR's contents. \n" \
"> see the [tools guide](https://github.com/Codium-ai/pr-agent/blob/main/docs/TOOLS_GUIDE.md) for more details.\n\n" \
">To edit any configuration parameter from the [configuration.toml](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml), add --config_path=new_value.\n" \
">For example: /review --pr_reviewer.extra_instructions=\"focus on the file: ...\" \n" \
">To list the possible configuration parameters, add a **/config** comment.\n" \
">To edit any configuration parameter from the [configuration.toml](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml), add --config_path=new_value. \n" \
">For example: /review --pr_reviewer.extra_instructions=\"focus on the file: ...\" \n" \
">To list the possible configuration parameters, add a **/config** comment. \n" \


def bot_help_text(user: str):
return f"> Tag me in a comment '@{user}' and add one of the following commands:\n" + commands_text
return f"> Tag me in a comment '@{user}' and add one of the following commands: \n" + commands_text


actions_help_text = "> To invoke the PR-Agent, add a comment using one of the following commands:\n" + \
actions_help_text = "> To invoke the PR-Agent, add a comment using one of the following commands: \n" + \
commands_text
5 changes: 4 additions & 1 deletion pr_agent/settings/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ keep_original_user_title=false
use_bullet_points=true
extra_instructions = ""
enable_pr_type=true
enable_file_walkthrough=false
enable_semantic_files_types=true
final_update_message = true


# markers
use_description_markers=false
include_generated_by_header=true

#custom_labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation', 'Other']
#custom_labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Enhancement', 'Documentation', 'Other']

[pr_questions] # /ask #

Expand Down
4 changes: 1 addition & 3 deletions pr_agent/settings/custom_labels.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ enable_custom_labels=false
#description = """Adds or modifies tests"""
#[custom_labels."Bug fix with tests"]
#description = """Fixes a bug in the code and adds or modifies tests"""
#[custom_labels."Refactoring"]
#description = """Code refactoring without changing functionality"""
#[custom_labels."Enhancement"]
#description = """Adds new features or functionality"""
#description = """Adds new features or modifies existing ones"""
#[custom_labels."Documentation"]
#description = """Adds or modifies documentation"""
#[custom_labels."Other"]
Expand Down
1 change: 0 additions & 1 deletion pr_agent/settings/pr_custom_labels.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ The output must be a YAML object equivalent to type $Labels, according to the fo
class Label(str, Enum):
bug_fix = "Bug fix"
tests = "Tests"
refactoring = "Refactoring"
enhancement = "Enhancement"
documentation = "Documentation"
other = "Other"
Expand Down
31 changes: 28 additions & 3 deletions pr_agent/settings/pr_description_prompts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ The output must be a YAML object equivalent to type $PRDescription, according to
class PRType(str, Enum):
bug_fix = "Bug fix"
tests = "Tests"
refactoring = "Refactoring"
enhancement = "Enhancement"
documentation = "Documentation"
other = "Other"
Expand All @@ -31,18 +30,32 @@ class PRType(str, Enum):

{%- endif %}

{%- if enable_file_walkthrough %}
class FileWalkthrough(BaseModel):
filename: str = Field(description="the relevant file full path")
changes_in_file: str = Field(description="minimal and concise description of the changes in the relevant file")
changes_in_file: str = Field(description="minimal and concise summary of the changes in the relevant file")
{%- endif %}

{%- if enable_semantic_files_types %}
Class FileDescription(BaseModel):
filename: str = Field(description="the relevant file full path")
changes_summary: str = Field(description="minimal and concise summary of the changes in the relevant file")
label: str = Field(description="a single semantic label that represents a type of code changes that occurred in the File. Possible values (partial list): 'bug fix', 'tests', 'enhancement', 'documentation', 'error handling', 'configuration changes', 'dependencies', 'formatting', 'miscellaneous', ...")
{%- endif %}

Class PRDescription(BaseModel):
title: str = Field(description="an informative title for the PR, describing its main theme")
type: List[PRType] = Field(description="one or more types that describe the PR type. . Return the label value, not the name.")
type: List[PRType] = Field(description="one or more types that describe the PR type. Return the label value, not the name.")
description: str = Field(description="an informative and concise description of the PR. {%- if use_bullet_points %} Use bullet points.{% endif %}")
{%- if enable_custom_labels %}
labels: List[Label] = Field(min_items=0, description="custom labels that describe the PR. Return the label value, not the name.")
{%- endif %}
{%- if enable_file_walkthrough %}
main_files_walkthrough: List[FileWalkthrough] = Field(max_items=10)
{%- endif %}
{%- if enable_semantic_files_types %}
pr_files[List[FileDescription]] = Field(max_items=15")
{%- endif %}
=====


Expand All @@ -61,9 +74,21 @@ labels:
{%- endif %}
description: |-
...
{%- if enable_file_walkthrough %}
main_files_walkthrough:
- ...
- ...
{%- endif %}
{%- if enable_semantic_files_types %}
pr_files:
- filename: |
...
changes_summary: |
...
label: |
...
...
{%- endif %}
```

Answer should be a valid YAML, and nothing else. Each YAML output MUST be after a newline, with proper indent, and block scalar indicator ('|-')
Expand Down
1 change: 0 additions & 1 deletion pr_agent/settings/pr_reviewer_prompts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ PR Analysis:
enum:
- Bug fix
- Tests
- Refactoring
- Enhancement
- Documentation
- Other
Expand Down
Loading
Loading