-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathvalidate-exercise-config.py
More file actions
89 lines (76 loc) · 2.88 KB
/
validate-exercise-config.py
File metadata and controls
89 lines (76 loc) · 2.88 KB
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
# Script to verify that all exercise configurations are compliant with the expected format
import json
import os
import pathlib
import subprocess
import sys
from dataclasses import dataclass
from typing import List, Set
# List of exercises to exempt, maybe because these have not been updated or are deprecated exercises
EXEMPTION_LIST: Set[str] = set()
@dataclass
class ValidationIssue:
dir_name: str
issue: str
def main() -> None:
issues: List[ValidationIssue] = []
for dir in os.listdir("."):
if dir in EXEMPTION_LIST or not os.path.isfile(
pathlib.Path(dir) / ".gitmastery-exercise.json"
):
continue
config = {}
with open(pathlib.Path(dir) / ".gitmastery-exercise.json", "r") as config_file:
config = json.loads(config_file.read())
if config["exercise_name"].strip() == "":
issues.append(
ValidationIssue(dir, "Empty exercise_name is not permitted")
)
if config.get("exercise_repo", {}).get(
"repo_type", "local"
) == "remote" and not config.get("requires_github", False):
issues.append(
ValidationIssue(
dir,
"Cannot use 'remote' repo_type if require_github is disabled",
)
)
if (
config.get("exercise_repo", {}).get("repo_type", "local") == "local"
and not config.get("requires_git", False)
and config.get("exercise_repo", {}).get("init", False)
):
issues.append(
ValidationIssue(
dir,
"Cannot use 'local' repo_type with init: true if require_git is disabled",
)
)
if (
config.get("exercise_repo", {}).get("repo_type", "local") == "remote"
and subprocess.call(
[
"git",
"ls-remote",
f"https://github.com/git-mastery/{config['exercise_repo']['repo_title']}",
"--quiet",
]
)
!= 0
):
issues.append(
ValidationIssue(
dir, "Missing Github repository to fetch for remote exercise"
)
)
for file in config["base_files"].keys():
if not os.path.isfile(pathlib.Path(dir) / "res" / file):
issues.append(
ValidationIssue(dir, f"Missing file {file} from res/")
)
if len(issues) > 0:
for issue in issues:
print(f"- {issue.dir_name}: {issue.issue}")
sys.exit(1)
if __name__ == "__main__":
main()