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": |
Raffael Meyer | f2206c2 | 2020-12-15 05:05:16 +0100 | [diff] [blame] | 24 | parts = parsed_url.path.split('/') |
| 25 | if len(parts) == 5 and parts[1] == "frappe" and parts[2] in docs_repos: |
Suraj Shetty | 0a6770a | 2020-10-14 10:21:31 +0530 | [diff] [blame] | 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() |
Ankush Menat | 8bbec42 | 2021-08-17 15:14:13 +0530 | [diff] [blame] | 35 | title = (payload.get("title") or "").lower().strip() |
| 36 | head_sha = (payload.get("head") or {}).get("sha") |
| 37 | body = (payload.get("body") or "").lower() |
Suraj Shetty | 0a6770a | 2020-10-14 10:21:31 +0530 | [diff] [blame] | 38 | |
Ankush Menat | 2a43fe1 | 2021-08-16 18:03:21 +0530 | [diff] [blame] | 39 | if (title.startswith("feat") |
| 40 | and head_sha |
| 41 | and "no-docs" not in body |
| 42 | and "backport" not in body |
| 43 | ): |
Suraj Shetty | 0a6770a | 2020-10-14 10:21:31 +0530 | [diff] [blame] | 44 | if docs_link_exists(body): |
| 45 | print("Documentation Link Found. You're Awesome! 🎉") |
| 46 | |
| 47 | else: |
| 48 | print("Documentation Link Not Found! ⚠️") |
| 49 | sys.exit(1) |
| 50 | |
| 51 | else: |
| 52 | print("Skipping documentation checks... 🏃") |