gh_status.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import datetime
  2. import platform
  3. from github.PullRequest import PullRequest
  4. def get_timestamp():
  5. return datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")
  6. def get_platform_name():
  7. return f'{platform.system().lower()}-{platform.machine()}'
  8. def update_pr_comment_text(pr: PullRequest, build_preset: str, run_number: int, color: str, text: str, rewrite: bool):
  9. platform_name = get_platform_name()
  10. header = f"<!-- status pr={pr.number}, preset={platform_name}-{build_preset}, run={run_number} -->"
  11. body = comment = None
  12. for c in pr.get_issue_comments():
  13. if c.body.startswith(header):
  14. print(f"found comment id={c.id}")
  15. comment = c
  16. if not rewrite:
  17. body = [c.body]
  18. break
  19. if body is None:
  20. body = [header]
  21. indicator = f":{color}_circle:"
  22. body.append(f"{indicator} `{get_timestamp()}` {text}")
  23. body = "\n".join(body)
  24. if '{platform_name}' in body:
  25. # input can contain '{platform_name}'
  26. body = body.replace('{platform_name}', platform_name)
  27. if comment is None:
  28. print(f"post new comment")
  29. pr.create_issue_comment(body)
  30. else:
  31. print(f"edit comment")
  32. comment.edit(body)