forked from xbmc/addon-check
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_repo.py
59 lines (46 loc) · 2 KB
/
check_repo.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
import os
import sys
import json
import check_addon
from common import colorPrint
from git_comments import GithubAPI
def _read_config_for_version(repo_path):
config_path = os.path.join(repo_path, '.tests-config.json')
if os.path.isfile(config_path):
with open(config_path) as json_data:
return json.load(json_data)
return None
def check_repo():
error_counter = {"warnings": 0, "problems": 0}
repo_path = os.path.abspath(os.path.join(
os.path.dirname(os.path.realpath(__file__)), os.pardir))
print("Repo path " + repo_path)
parameters = sys.argv[1:]
if len(parameters) == 0:
toplevel_folders = sorted(next(os.walk(repo_path))[1])
else:
toplevel_folders = sorted(parameters)
print("Toplevel folders " + str(toplevel_folders))
config = _read_config_for_version(repo_path)
for addon_folder in toplevel_folders:
if addon_folder[0] != '.':
addon_path = os.path.join(repo_path, addon_folder)
error_counter = check_addon.start(
error_counter, addon_path, config)
if check_addon.check_config(config, "comment_on_pull"):
if check_addon.comments_problem or check_addon.comments_warning:
GithubAPI().comment_on_pull(check_addon.comments_problem, check_addon.comments_warning)
GithubAPI().set_label(["Checks failed"])
else:
GithubAPI().remove_label(["Checks failed"])
GithubAPI().set_label(["Checks passed"])
if error_counter["problems"] > 0:
colorPrint("We found %s problems and %s warnings, please check the logfile." % (
error_counter["problems"], error_counter["warnings"]), "31")
sys.exit(1)
elif error_counter["warnings"] > 0:
# If we only found warnings, don't mark the build as broken
colorPrint("We found %s problems and %s warnings, please check the logfile." % (
error_counter["problems"], error_counter["warnings"]), "35")
print("Finished!")
check_repo()