選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

65 行
1.7 KiB

  1. import sys
  2. from urllib.parse import urlparse
  3. import requests
  4. WEBSITE_REPOS = [
  5. "xhiveerp_com",
  6. "xhiveframework_io",
  7. ]
  8. DOCUMENTATION_DOMAINS = [
  9. "docs.xhiveerp.com",
  10. "xhiveframework.com",
  11. ]
  12. def is_valid_url(url: str) -> bool:
  13. parts = urlparse(url)
  14. return all((parts.scheme, parts.netloc, parts.path))
  15. def is_documentation_link(word: str) -> bool:
  16. if not word.startswith("http") or not is_valid_url(word):
  17. return False
  18. parsed_url = urlparse(word)
  19. if parsed_url.netloc in DOCUMENTATION_DOMAINS:
  20. return True
  21. if parsed_url.netloc == "github.com":
  22. parts = parsed_url.path.split("/")
  23. if len(parts) == 5 and parts[1] == "xhiveframework" and parts[2] in WEBSITE_REPOS:
  24. return True
  25. return False
  26. def contains_documentation_link(body: str) -> bool:
  27. return any(is_documentation_link(word) for line in body.splitlines() for word in line.split())
  28. def check_pull_request(number: str) -> "tuple[int, str]":
  29. response = requests.get(f"https://api.github.com/repos/xhiveframework/xhiveframework/pulls/{number}")
  30. if not response.ok:
  31. return 1, "Pull Request Not Found! ⚠️"
  32. payload = response.json()
  33. title = (payload.get("title") or "").lower().strip()
  34. head_sha = (payload.get("head") or {}).get("sha")
  35. body = (payload.get("body") or "").lower()
  36. if not title.startswith("feat") or not head_sha or "no-docs" in body or "backport" in body:
  37. return 0, "Skipping documentation checks... 🏃"
  38. if contains_documentation_link(body):
  39. return 0, "Documentation Link Found. You're Awesome! 🎉"
  40. return 1, "Documentation Link Not Found! ⚠️"
  41. if __name__ == "__main__":
  42. exit_code, message = check_pull_request(sys.argv[1])
  43. print(message)
  44. sys.exit(exit_code)