-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcheck_keys.py
147 lines (128 loc) · 5.92 KB
/
check_keys.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import yaml
REQUIRED_KEYS_PROJECT = {
"name": str,
"groups": list,
"founder": bool,
"contributor": bool,
"maintainer": bool,
"involved": bool,
}
OPTIONAL_KEYS_PROJECT = {
"description": str,
"license": str,
"website": str,
"repository": str,
"logo": str,
}
REQUIRED_KEYS_GROUP = {
"name": str,
"handle": str,
}
OPTIONAL_KEYS_GROUP = {
"website": str,
}
with open("oss-projects.yaml", "r") as f:
projects = yaml.load(f, Loader=yaml.Loader)
with open("cs-groups.yaml", "r") as f:
groups = yaml.load(f, Loader=yaml.Loader)
project_problems = {}
group_problems = {}
missing_key = "Missing key: "
value_error = "value error:"
for idx, project in enumerate(projects):
for key in REQUIRED_KEYS_PROJECT:
if key not in project:
if idx not in project_problems:
project_problems[idx] = [missing_key + key]
else:
project_problems[idx].append(missing_key + key)
else:
if not isinstance(project[key], REQUIRED_KEYS_PROJECT[key]):
if idx not in project_problems:
project_problems[idx] = [f"[{key}] {value_error} expected {REQUIRED_KEYS_PROJECT[key].__name__}"]
else:
project_problems[idx].append(f"[{key}] {value_error} expected {REQUIRED_KEYS_PROJECT[key].__name__}")
if isinstance(project[key], str):
if len(project[key]) == 0:
if idx not in project_problems:
project_problems[idx] = [f"[{key}] {value_error} expected non-empty string"]
else:
project_problems[idx].append(f"[{key}] {value_error} expected non-empty string")
for key in OPTIONAL_KEYS_PROJECT:
if key in project:
if not isinstance(project[key], OPTIONAL_KEYS_PROJECT[key]):
if idx not in project_problems:
project_problems[idx] = [f"(Optional Key) [{key}] {value_error} expected {OPTIONAL_KEYS_PROJECT[key].__name__}"]
else:
project_problems[idx].append(f"(Optional Key) [{key}] {value_error} expected {OPTIONAL_KEYS_PROJECT[key].__name__}")
if isinstance(project[key], str):
if len(project[key]) == 0:
if idx not in project_problems:
project_problems[idx] = [f"(Optional Key) [{key}] {value_error} expected non-empty string"]
else:
project_problems[idx].append(f"(Optional Key) [{key}] {value_error} expected non-empty string")
for idx, group in enumerate(groups):
for key in REQUIRED_KEYS_GROUP:
if key not in group:
if idx not in group_problems:
group_problems[idx] = [missing_key + key]
else:
group_problems[idx].append(missing_key + key)
else:
if not isinstance(group[key], REQUIRED_KEYS_GROUP[key]):
if idx not in group_problems:
group_problems[idx] = [f"[{key}] {value_error} expected {REQUIRED_KEYS_GROUP[key].__name__}"]
else:
group_problems[idx].append(f"[{key}] {value_error} expected {REQUIRED_KEYS_GROUP[key].__name__}")
if isinstance(group[key], str):
if len(group[key]) == 0:
if idx not in group_problems:
group_problems[idx] = [f"[{key}] {value_error} expected non-empty string"]
else:
group_problems[idx].append(f"[{key}] {value_error} expected non-empty string")
for key in OPTIONAL_KEYS_GROUP:
if key in group:
if not isinstance(group[key], OPTIONAL_KEYS_GROUP[key]):
if idx not in group_problems:
group_problems[idx] = [f"(Optional Key) [{key}] {value_error} expected {OPTIONAL_KEYS_GROUP[key].__name__}"]
else:
group_problems[idx].append(f"(Optional Key) [{key}] {value_error} expected {OPTIONAL_KEYS_GROUP[key].__name__}")
if isinstance(group[key], str):
if len(group[key]) == 0:
if idx not in group_problems:
group_problems[idx] = [f"(Optional Key) [{key}] {value_error} expected non-empty string"]
else:
group_problems[idx].append(f"(Optional Key) [{key}] {value_error} expected non-empty string")
summary = "# Check of projects.yaml file\n"
if len(project_problems) == 0:
summary += "✅ No problems in oss-projects yaml found"
print(summary)
else:
summary += "❌ Missing keys in oss-projects yaml\n"
summary += "| Project index | Project name (if available) | Problems |\n"
summary += "| ------------- | --------------------------- | -------- |\n"
for project_idx, keys in project_problems.items():
if "name" not in keys:
project_name = projects[project_idx]["name"]
else:
project_name = "N/A"
summary += f"| {project_idx} | {project_name} | {', '.join(keys)} |\n"
print(summary)
print("")
summary = "# Check of cs-groups.yaml file\n"
if len(group_problems) == 0:
summary += "✅ No problems in cs-groups yaml found"
print(summary)
else:
summary += "❌ Missing keys in cs-groups yaml\n"
summary += "| Group index | Group name (if available) | Problems |\n"
summary += "| ----------- | -------------------------- | -------- |\n"
for group_idx, keys in group_problems.items():
if "name" not in keys:
group_name = groups[group_idx]["name"]
else:
group_name = "N/A"
summary += f"| {group_idx} | {group_name} | {', '.join(keys)} |\n"
print(summary)
if (len(project_problems) != 0) or (len(group_problems) != 0):
raise KeyError("Required keys (information about the open source project) are missing in oss-projects.yaml or cs-groups.yaml.")