25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

74 lines
1.6 KiB

  1. import sys
  2. import requests
  3. from urllib.parse import urlparse
  4. WEBSITE_REPOS = [
  5. "erpnext_com",
  6. "frappe_io",
  7. ]
  8. DOCUMENTATION_DOMAINS = [
  9. "docs.erpnext.com",
  10. "frappeframework.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] == "frappe" and parts[2] in WEBSITE_REPOS:
  24. return True
  25. return False
  26. def contains_documentation_link(body: str) -> bool:
  27. return any(
  28. is_documentation_link(word)
  29. for line in body.splitlines()
  30. for word in line.split()
  31. )
  32. def check_pull_request(number: str) -> "tuple[int, str]":
  33. response = requests.get(f"https://api.github.com/repos/frappe/erpnext/pulls/{number}")
  34. if not response.ok:
  35. return 1, "Pull Request Not Found! ⚠️"
  36. payload = response.json()
  37. title = (payload.get("title") or "").lower().strip()
  38. head_sha = (payload.get("head") or {}).get("sha")
  39. body = (payload.get("body") or "").lower()
  40. if (
  41. not title.startswith("feat")
  42. or not head_sha
  43. or "no-docs" in body
  44. or "backport" in body
  45. ):
  46. return 0, "Skipping documentation checks... 🏃"
  47. if contains_documentation_link(body):
  48. return 0, "Documentation Link Found. You're Awesome! 🎉"
  49. return 1, "Documentation Link Not Found! ⚠️"
  50. if __name__ == "__main__":
  51. exit_code, message = check_pull_request(sys.argv[1])
  52. print(message)
  53. sys.exit(exit_code)