Skip to content

Commit

Permalink
Merge pull request Codium-ai#565 from Codium-ai/tr/remove_old_walkthr…
Browse files Browse the repository at this point in the history
…ough

Remove old 'enable_file_walkthrough' mode
  • Loading branch information
mrT23 committed Jan 4, 2024
2 parents 1bba016 + ed78bfd commit 92f89e6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
3 changes: 2 additions & 1 deletion docs/DESCRIBE.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ Under the section 'pr_description', the [configuration file](./../pr_agent/setti

- `final_update_message`: if set to true, it will add a comment message [`PR Description updated to latest commit...`](https://github.com/Codium-ai/pr-agent/pull/499#issuecomment-1837412176) after finishing calling `/describe`. Default is true.

- `enable_semantic_files_types`: if set to true, "PR changes walkthrough" section will be generated. Default is true.
- `enable_semantic_files_types`: if set to true, "Changes walkthrough" section will be generated. Default is true.
- `collapsible_file_list`: if set to true, the file list in the "Changes walkthrough" section will be collapsible. If set to "adaptive", the file list will be collapsible only if there are more than 8 files. Default is "adaptive".

### Markers template

Expand Down
7 changes: 3 additions & 4 deletions pr_agent/settings/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ 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


## changes walkthrough section
enable_semantic_files_types=true
collapsible_file_list='adaptive' # true, false, 'adaptive'
# markers
use_description_markers=false
include_generated_by_header=true
Expand Down
6 changes: 0 additions & 6 deletions pr_agent/settings/pr_description_prompts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ 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 summary of the changes in the relevant file")
{%- endif %}
{%- if enable_semantic_files_types %}
Class FileDescription(BaseModel):
Expand Down
38 changes: 23 additions & 15 deletions pr_agent/tools/pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def __init__(self, pr_url: str, args: list = None,
"commit_messages_str": self.git_provider.get_commit_messages(),
"enable_custom_labels": get_settings().config.enable_custom_labels,
"custom_labels_class": "", # will be filled if necessary in 'set_custom_labels' function
"enable_file_walkthrough": get_settings().pr_description.enable_file_walkthrough,
"enable_semantic_files_types": get_settings().pr_description.enable_semantic_files_types,
}

Expand Down Expand Up @@ -247,16 +246,15 @@ def _prepare_pr_answer_with_markers(self) -> Tuple[str, str]:
summary = f"{ai_header}{ai_summary}"
body = body.replace('pr_agent:summary', summary)

if not re.search(r'<!--\s*pr_agent:walkthrough\s*-->', body):
ai_walkthrough = self.data.get('PR Main Files Walkthrough')
if ai_walkthrough:
walkthrough = str(ai_header)
for file in ai_walkthrough:
filename = file['filename'].replace("'", "`")
description = file['changes in file'].replace("'", "`")
walkthrough += f'- `{filename}`: {description}\n'

body = body.replace('pr_agent:walkthrough', walkthrough)
ai_walkthrough = self.data.get('pr_files')
if ai_walkthrough and not re.search(r'<!--\s*pr_agent:walkthrough\s*-->', body):
try:
walkthrough_gfm = ""
walkthrough_gfm = self.process_pr_files_prediction(walkthrough_gfm, self.file_label_dict)
body = body.replace('pr_agent:walkthrough', walkthrough_gfm)
except Exception as e:
get_logger().error(f"Failing to process walkthrough {self.pr_id}: {e}")
body = body.replace('pr_agent:walkthrough', "")

return title, body

Expand Down Expand Up @@ -295,7 +293,7 @@ def _prepare_pr_answer(self) -> Tuple[str, str]:
for idx, (key, value) in enumerate(self.data.items()):
if key == 'pr_files':
value = self.file_label_dict
key_publish = "PR changes walkthrough"
key_publish = "Changes walkthrough"
else:
key_publish = key.rstrip(':').replace("_", " ").capitalize()
pr_body += f"## {key_publish}\n"
Expand Down Expand Up @@ -329,7 +327,7 @@ def _prepare_file_labels(self):
try:
filename = file['filename'].replace("'", "`").replace('"', '`')
changes_summary = file['changes_summary']
label = file['label']
label = file.get('label')
if label not in self.file_label_dict:
self.file_label_dict[label] = []
self.file_label_dict[label].append((filename, changes_summary))
Expand All @@ -338,6 +336,9 @@ def _prepare_file_labels(self):
pass

def process_pr_files_prediction(self, pr_body, value):
use_collapsible_file_list = get_settings().pr_description.collapsible_file_list
if use_collapsible_file_list == "adaptive":
use_collapsible_file_list = len(value) > 8
if not self.git_provider.is_supported("gfm_markdown"):
get_logger().info(f"Disabling semantic files types for {self.pr_id} since gfm_markdown is not supported")
return pr_body
Expand All @@ -352,7 +353,11 @@ def process_pr_files_prediction(self, pr_body, value):
s_label = semantic_label.strip("'").strip('"')
pr_body += f"""<tr><td><strong>{s_label.capitalize()}</strong></td>"""
list_tuples = value[semantic_label]
pr_body += f"""<td><details><summary>{len(list_tuples)} files</summary><table>"""

if use_collapsible_file_list:
pr_body += f"""<td><details><summary>{len(list_tuples)} files</summary><table>"""
else:
pr_body += f"""<td><table>"""
for filename, file_change_description in list_tuples:
filename = filename.replace("'", "`")
filename_publish = filename.split("/")[-1]
Expand Down Expand Up @@ -391,7 +396,10 @@ def process_pr_files_prediction(self, pr_body, value):
</tr>
"""
pr_body += """</table></details></td></tr>"""
if use_collapsible_file_list:
pr_body += """</table></details></td></tr>"""
else:
pr_body += """</table></td></tr>"""
pr_body += """</tr></tbody></table>"""

except Exception as e:
Expand Down

0 comments on commit 92f89e6

Please sign in to comment.