-
Notifications
You must be signed in to change notification settings - Fork 3
/
pre-commit.example
62 lines (50 loc) · 1.89 KB
/
pre-commit.example
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
#!/usr/bin/env python
#Warning, this is cursed.
import execjs
import sys
import re
with open(".git/hooks/pre-commit", 'r') as file:
this_file = file.read()
with open("pre-commit.example", 'w') as file:
file.write(this_file)
with open("variant-list.js", 'r', encoding='utf-8') as file:
data = file.read()
ctx = execjs.compile(re.sub(r'[^\x00-\x7F]', '?', data))
data = ctx.eval("variant_list_data")
accepted = True
REQUIRED_VALUES = ["tags","color","credit","description","min_teams","max_teams","min_players_per_team","max_players_per_team"]
VALID_COLORS = ["White", "Purple", "Blue", "Green", "Orange", "Red"]
VALID_VALUES = ["name","tags","color","credit","description","external_links","notes","min_teams","max_teams","min_players_per_team","max_players_per_team","player_count_override"]
for variant in data:
if not "name" in variant.keys():
print("Theres a variant without a name")
accepted = False
continue
name = variant["name"]
for val in variant.keys():
if not val in VALID_VALUES:
print(f"Variant {name} has field {val}, this is not a valid field.")
accepted = False
everything_present = True
for val in REQUIRED_VALUES:
if not val in variant.keys():
print(f"Variant {name} does not have a {val} field.")
everything_present = False
accepted = False
if not everything_present:
continue
if not variant["color"] in VALID_COLORS:
print(f"Variant {name} does not have a valid color. ({variant['color']}) (You might have forgotten to capitalize)")
accepted = False
if "external_links" in variant.keys():
links = variant["external_links"]
for link in links:
if not "name" in link.keys():
print(f"Variant {name} has a external_link without a name.")
accepted = False
if not ("link" in link.keys() or "file" in link.keys()):
print(f"Variant {name} has a external_link without a link or file.")
accepted = False
if accepted:
sys.exit(0)
sys.exit(1)