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

Refactor EARBotReviewer to handle merged but unreviewed reports #130

Merged
merged 2 commits into from
Jan 17, 2025
Merged
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
39 changes: 25 additions & 14 deletions ear_bot/ear_bot_reviewer.py
Original file line number Diff line number Diff line change
@@ -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
@@ -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!")