forked from Showndarya/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.py
64 lines (51 loc) · 1.97 KB
/
.travis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import json
import os
import re
import subprocess
# Get a diff between master and current.
try:
commit_range = os.environ["TRAVIS_COMMIT_RANGE"]
changed_files = subprocess.check_output(["git", "diff", "--name-only", commit_range])
except KeyError:
print("🔥 This should be run on Travis. Otherwise make sure TRAVIS_BRANCH is set.")
exit(1)
# Filter JSON files only.
changed_files_json = []
if changed_files:
changed_files = changed_files.decode()
for changed_file in changed_files.split('\n'):
if re.search(r"\.json$", changed_file):
changed_files_json.append(changed_file)
# Iterate over list of changed JSON files.
for changed_file_json in changed_files_json:
print(f"Checking file {changed_file_json}...")
there_was_an_error = False
if not os.path.basename(changed_file_json)[0].isupper():
there_was_an_error = True
print("🔥 File name not capitalized.")
try:
with open(changed_file_json) as data_file:
file_content = json.loads(data_file.read())
except json.decoder.JSONDecodeError:
there_was_an_error = True
print("🔥 JSON could not be parsed.")
if 'word' not in file_content:
there_was_an_error = True
print("🔥 Key 'word' not found.")
if not file_content["word"]:
there_was_an_error = True
print("🔥 Value for 'word' appears to be empty.")
if 'definitions' not in file_content:
there_was_an_error = True
print("🔥 Key 'definitions' not found.")
if not file_content["definitions"]:
there_was_an_error = True
print("🔥 Value for 'definitions' appears to be empty.")
if 'parts-of-speech' not in file_content:
there_was_an_error = True
print("🔥 Key 'parts-of-speech' not found.")
if not file_content["parts-of-speech"]:
there_was_an_error = True
print("🔥 Value for 'parts-of-speech' appears to be empty.")
if there_was_an_error:
exit(1)