feat: Refactor PR files processing into separate function in pr_description.py

This commit is contained in:
mrT23
2023-12-06 17:01:21 +02:00
parent 93b6d31505
commit a61e492fe1

View File

@ -281,8 +281,42 @@ class PRDescription:
description = file['changes_in_file']
pr_body += f'- `{filename}`: {description}\n'
if self.git_provider.is_supported("gfm_markdown"):
pr_body +="</details>\n"
pr_body += "</details>\n"
elif 'pr_files' in key.lower():
pr_body = self.process_pr_files_prediction(pr_body, value)
else:
# if the value is a list, join its items by comma
if isinstance(value, list):
value = ', '.join(v for v in value)
pr_body += f"{value}\n"
if idx < len(self.data) - 1:
pr_body += "\n___\n"
if get_settings().config.verbosity_level >= 2:
get_logger().info(f"title:\n{title}\n{pr_body}")
return title, pr_body
def _prepare_file_labels(self):
self.file_label_dict = {}
for file in self.data['pr_files']:
try:
filename = file['filename'].replace("'", "`").replace('"', '`')
changes_summary = file['changes_summary']
label = file['label']
if label not in self.file_label_dict:
self.file_label_dict[label] = []
self.file_label_dict[label].append((filename, changes_summary))
except Exception as e:
get_logger().error(f"Error preparing file label dict {self.pr_id}: {e}")
pass
def process_pr_files_prediction(self, pr_body, value):
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
try:
pr_body += """\n| | Relevant Files """
pr_body += "&nbsp; " * 70
pr_body += """|\n|-----------|-------------|\n"""
@ -312,45 +346,23 @@ class PRDescription:
link = self.git_provider.get_line_link(filename, relevant_line_start=-1)
if link:
diff_plus_minus = f"[{diff_plus_minus}]({link})"
diff_plus_minus= f" <sup>{diff_plus_minus}</sup>"
diff_plus_minus = f" <sup>{diff_plus_minus}</sup>"
if diff_plus_minus:
filename_publish += diff_plus_minus
if self.git_provider.is_supported("gfm_markdown"):
pr_body += f"<details><summary>{filename_publish}</summary>"
file_change_description= self._insert_br_after_x_chars(file_change_description)
file_change_description = self._insert_br_after_x_chars(file_change_description)
if diff_plus_minus:
pr_body += f"<ul>Changes summary:<br>**{file_change_description}**</ul></details>"
else:
pr_body += f"<ul>Changes summary:<br>**{file_change_description}**</ul></details>"
if self.git_provider.is_supported("gfm_markdown"):
pr_body += "</ul></details>|\n"
else:
# if the value is a list, join its items by comma
if isinstance(value, list):
value = ', '.join(v for v in value)
pr_body += f"{value}\n"
if idx < len(self.data) - 1:
pr_body += "\n___\n"
if get_settings().config.verbosity_level >= 2:
get_logger().info(f"title:\n{title}\n{pr_body}")
return title, pr_body
def _prepare_file_labels(self):
self.file_label_dict = {}
for file in self.data['pr_files']:
try:
filename = file['filename'].replace("'", "`").replace('"', '`')
changes_summary = file['changes_summary']
label = file['label']
if label not in self.file_label_dict:
self.file_label_dict[label] = []
self.file_label_dict[label].append((filename, changes_summary))
except Exception as e:
get_logger().error(f"Error preparing file label dict {self.pr_id}: {e}")
get_logger().error(f"Error processing pr files to markdown {self.pr_id}: {e}")
pass
return pr_body
def _insert_br_after_x_chars(self, text):
"""