blob: 378983e95f2a4757a7c456cd46cee6a870828efc [file] [log] [blame]
Suraj Shetty0a6770a2020-10-14 10:21:31 +05301import sys
2import requests
3from urllib.parse import urlparse
4
5
6docs_repos = [
7 "frappe_docs",
8 "erpnext_documentation",
9 "erpnext_com",
10 "frappe_io",
11]
12
13
14def uri_validator(x):
15 result = urlparse(x)
16 return all([result.scheme, result.netloc, result.path])
17
18def 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 Meyerf2206c22020-12-15 05:05:16 +010024 parts = parsed_url.path.split('/')
25 if len(parts) == 5 and parts[1] == "frappe" and parts[2] in docs_repos:
Suraj Shetty0a6770a2020-10-14 10:21:31 +053026 return True
Ankush Menat55969882021-09-07 14:53:30 +053027 elif parsed_url.netloc == "docs.erpnext.com":
28 return True
Suraj Shetty0a6770a2020-10-14 10:21:31 +053029
30
31if __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 Menat8bbec422021-08-17 15:14:13 +053037 title = (payload.get("title") or "").lower().strip()
38 head_sha = (payload.get("head") or {}).get("sha")
39 body = (payload.get("body") or "").lower()
Suraj Shetty0a6770a2020-10-14 10:21:31 +053040
Ankush Menat2a43fe12021-08-16 18:03:21 +053041 if (title.startswith("feat")
42 and head_sha
43 and "no-docs" not in body
44 and "backport" not in body
45 ):
Suraj Shetty0a6770a2020-10-14 10:21:31 +053046 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... 🏃")