"""
Post the comment like the following to the PR:
```
:robot: TeamCity test results bot :robot:

<Logs from pytest>
```
"""

from github import Github
import os
import sys

# Check if this is a pull request or not based on the environment variable
try:
    pr_id = int(os.environ["GITHUB_PR_NUMBER"].split("/")[-1])
except Exception:
    sys.exit(0)
header = """
<h2 align="center">:robot: TeamCity test results bot :robot:</h2>

"""

pytest_outputs = ["ray_tests.log", "dask_tests.log", "python_tests.log"]

full_comment = header

for out in pytest_outputs:

    full_comment += "<details><summary>{} Tests</summary>\n".format(
        out.split("_")[0].title()
    )
    full_comment += "\n\n```\n"
    full_comment += open(out, "r").read()
    full_comment += "\n```\n\n</details>\n"

token = os.environ["GITHUB_TOKEN"]
g = Github(token)
repo = g.get_repo("modin-project/modin")

pr = repo.get_pull(pr_id)
if any(i.user.login == "modin-bot" for i in pr.get_issue_comments()):
    pr_comment_list = [
        i for i in list(pr.get_issue_comments()) if i.user.login == "modin-bot"
    ]
    assert len(pr_comment_list) == 1, "Too many comments from modin-bot already"
    pr_comment_list[0].edit(full_comment)
else:
    pr.create_issue_comment(full_comment)

Add a bot message to display TeamCity test results
Add a bot message to display TeamCity test results

* Make modin-bot update the comment instead of creating a new one
* Also only run the comment bot when a PR is being evaluated

Signed-off-by: Devin Petersohn <9526cbaf745870a4c947dfa2bd5208403b463ac3@gmail.com>
