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 |
Ankush Menat | 5596988 | 2021-09-07 14:53:30 +0530 | [diff] [blame] | 27 | elif parsed_url.netloc == "docs.erpnext.com": |
| 28 | return True |
Suraj Shetty | 0a6770a | 2020-10-14 10:21:31 +0530 | [diff] [blame] | 29 | |
| 30 | |
| 31 | if __name__ == "__main__": |
| 32 | pr = sys.argv[1] |
| 33 | response = requests.get("https://api.github.com/repos/frappe/erpnext/pulls/{}".format(pr)) |
| 34 | |
| 35 | if response.ok: |
| 36 | payload = response.json() |
Ankush Menat | 8bbec42 | 2021-08-17 15:14:13 +0530 | [diff] [blame] | 37 | title = (payload.get("title") or "").lower().strip() |
| 38 | head_sha = (payload.get("head") or {}).get("sha") |
| 39 | body = (payload.get("body") or "").lower() |
Suraj Shetty | 0a6770a | 2020-10-14 10:21:31 +0530 | [diff] [blame] | 40 | |
Ankush Menat | 2a43fe1 | 2021-08-16 18:03:21 +0530 | [diff] [blame] | 41 | if (title.startswith("feat") |
| 42 | and head_sha |
| 43 | and "no-docs" not in body |
| 44 | and "backport" not in body |
| 45 | ): |
Suraj Shetty | 0a6770a | 2020-10-14 10:21:31 +0530 | [diff] [blame] | 46 | if docs_link_exists(body): |
| 47 | print("Documentation Link Found. You're Awesome! 🎉") |
| 48 | |
| 49 | else: |
| 50 | print("Documentation Link Not Found! ⚠️") |
| 51 | sys.exit(1) |
| 52 | |
| 53 | else: |
| 54 | print("Skipping documentation checks... 🏃") |