advchecks.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python
  2. import json
  3. def find_lgtms(comments):
  4. commenters = []
  5. for comment in comments:
  6. body = comment["body"].strip()
  7. if body == "/lgtm":
  8. commenters.append("%s(%s)" % (comment["user"]["login"], comment["user"]["id"]))
  9. return commenters
  10. def find_reviewers(pulls):
  11. reviewers = []
  12. for reviewer in pulls["requested_reviewers"]:
  13. reviewers.append("%s(%s)" % (reviewer["login"], reviewer["id"]))
  14. return reviewers
  15. if __name__ == '__main__':
  16. import sys
  17. if len(sys.argv) < 3:
  18. print(sys.argv[0], "<pull>", "<comment>")
  19. sys.exit(-1)
  20. with open(sys.argv[1]) as pullfile:
  21. pulls = json.load(pullfile)
  22. with open(sys.argv[2]) as commentfile:
  23. comments = json.load(commentfile)
  24. rvs = find_reviewers(pulls)
  25. cms = find_lgtms(comments)
  26. if len(rvs) == 0:
  27. print("No reviwer is assigned, give up check...")
  28. sys.exit(-1)
  29. print("Assigned reviwers: %s" % ", ".join(rvs))
  30. print("Lgtm reviwers: %s" % ", ".join(cms))
  31. req = []
  32. for rv in rvs:
  33. if rv not in cms:
  34. req.append(rv)
  35. if len(req) > 0:
  36. print("Reviewers %s needs /lgtm" % ",".join(req))
  37. sys.exit(-1)