Skip to content

Commit

Permalink
Refactor EARBotReviewer to handle merged but unreviewed reports (#130)
Browse files Browse the repository at this point in the history
* Refactor EARBotReviewer to support merged but not reviewed reports

* Update comment notification for YAML file addition in EARBotReviewer
  • Loading branch information
arash77 authored Jan 17, 2025
1 parent 872c61f commit 520d3a3
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions ear_bot/ear_bot_reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,26 +455,14 @@ 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"
f"Congratulations to {researcher_name} and the {institution} team for the high-quality assembly of _{species}_\n\n"
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
Expand All @@ -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 = []
Expand Down Expand Up @@ -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!")
Expand Down

0 comments on commit 520d3a3

Please sign in to comment.