Suraj Shetty | 0a6770a | 2020-10-14 10:21:31 +0530 | [diff] [blame] | 1 | import sys |
| 2 | import requests |
| 3 | from urllib.parse import urlparse |
| 4 | |
| 5 | |
| 6 | docs_repos = [ |
| 7 | "frappe_docs", |
| 8 | "erpnext_documentation", |
| 9 | "erpnext_com", |
| 10 | "frappe_io", |
| 11 | ] |
| 12 | |
| 13 | |
| 14 | def uri_validator(x): |
| 15 | result = urlparse(x) |
| 16 | return all([result.scheme, result.netloc, result.path]) |
| 17 | |
| 18 | def docs_link_exists(body): |
| 19 | for line in body.splitlines(): |
| 20 | for word in line.split(): |
| 21 | if word.startswith('http') and uri_validator(word): |
| 22 | parsed_url = urlparse(word) |
| 23 | if parsed_url.netloc == "github.com": |
| 24 | _, org, repo, _type, ref = parsed_url.path.split('/') |
| 25 | if org == "frappe" and repo in docs_repos: |
| 26 | return True |
| 27 | |
| 28 | |
| 29 | if __name__ == "__main__": |
| 30 | pr = sys.argv[1] |
| 31 | response = requests.get("https://api.github.com/repos/frappe/erpnext/pulls/{}".format(pr)) |
| 32 | |
| 33 | if response.ok: |
| 34 | payload = response.json() |
| 35 | title = payload.get("title", "").lower() |
| 36 | head_sha = payload.get("head", {}).get("sha") |
| 37 | body = payload.get("body", "").lower() |
| 38 | |
| 39 | if title.startswith("feat") and head_sha and "no-docs" not in body: |
| 40 | if docs_link_exists(body): |
| 41 | print("Documentation Link Found. You're Awesome! 🎉") |
| 42 | |
| 43 | else: |
| 44 | print("Documentation Link Not Found! ⚠️") |
| 45 | sys.exit(1) |
| 46 | |
| 47 | else: |
| 48 | print("Skipping documentation checks... 🏃") |