From 520d3a39577452171950603e42657c51efd97a63 Mon Sep 17 00:00:00 2001 From: Arash Kadkhodaei Date: Fri, 17 Jan 2025 15:12:06 +0100 Subject: [PATCH] Refactor EARBotReviewer to handle merged but unreviewed reports (#130) * Refactor EARBotReviewer to support merged but not reviewed reports * Update comment notification for YAML file addition in EARBotReviewer --- ear_bot/ear_bot_reviewer.py | 39 ++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/ear_bot/ear_bot_reviewer.py b/ear_bot/ear_bot_reviewer.py index 4825760..386b5bd 100644 --- a/ear_bot/ear_bot_reviewer.py +++ b/ear_bot/ear_bot_reviewer.py @@ -455,6 +455,7 @@ def closed_pr(self): for file in pr.get_files() if file.filename.lower().endswith(".pdf") ) + self._add_yaml_file(EAR_pdf.filename) EAR_pdf_url = re.sub(r"/blob/[\w\d]+/", "/blob/main/", EAR_pdf.blob_url) slack_post = ( f":tada: *New Assembly Finished!* :tada:\n\n" @@ -462,19 +463,6 @@ def closed_pr(self): f"The assembly was reviewed by {reviewer_name}, and the process supervised by {supervisor_name}. The EAR can be found in the following link:\n" f"{EAR_pdf_url}" ) - EARpdf_to_yaml_path = os.path.join(root_folder, "EARpdf_to_yaml.py") - EAR_pdf_file = os.path.join(root_folder, EAR_pdf.filename) - output_pdf_to_yaml = subprocess.run( - f"python {EARpdf_to_yaml_path} {EAR_pdf_file}", - shell=True, - capture_output=True, - text=True, - ) - yaml_file = EAR_pdf_file.replace(".pdf", ".yaml") - with open(yaml_file, "r") as file: - yaml_content = file.read() - commit(self.repo, yaml_file, "Add YAML file", yaml_content) - print(output_pdf_to_yaml.stdout, output_pdf_to_yaml.stderr) self._create_slack_post(slack_post) elif not merged: supervisor = pr.assignee.login @@ -485,8 +473,16 @@ def closed_pr(self): ) pr.add_to_labels("ERROR!") else: + EAR_pdf_filename = next( + file.filename + for file in pr.get_files() + if file.filename.lower().endswith(".pdf") + ) + self._add_yaml_file(EAR_pdf_filename) print("No review has been found for this merged PR.") - sys.exit(1) + pr.create_issue_comment( + "The YAML file has been updated based on the new EAR.pdf" + ) def _search_comment_user(self, pr, text_to_check): comment_user = [] @@ -569,6 +565,21 @@ def _create_slack_post(self, content): print(f"Slack post created: {link}") return True + def _add_yaml_file(self, EAR_pdf_filename): + EARpdf_to_yaml_path = os.path.join(root_folder, "EARpdf_to_yaml.py") + EAR_pdf_file = os.path.join(root_folder, EAR_pdf_filename) + output_pdf_to_yaml = subprocess.run( + f"python {EARpdf_to_yaml_path} {EAR_pdf_file}", + shell=True, + capture_output=True, + text=True, + ) + yaml_file = EAR_pdf_file.replace(".pdf", ".yaml") + with open(yaml_file, "r") as file: + yaml_content = file.read() + commit(self.repo, yaml_file, "Add YAML file", yaml_content) + print(output_pdf_to_yaml.stdout, output_pdf_to_yaml.stderr) + if __name__ == "__main__": parser = ArgumentParser(description="EAR bot!")