-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
80 lines (62 loc) · 3.55 KB
/
main.py
File metadata and controls
80 lines (62 loc) · 3.55 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
# usage : python main.py <token> <repository> <branch> <test-reports-path>
import os
import sys
import shutil
import argparse
from gamuLogger import Printer, deep_debug, debug, info, warning, error, critical, message, COLORS, chrono
from api import API
@chrono
def main(token, repository, branch, test_reports_path, simulate=False, clean=True):
if simulate:
message("Simulation mode is enabled, no changes will be made to the distant repository", COLORS.YELLOW)
token = bytes.fromhex(token).decode()
Printer.add_sensitive(token)
repository = repository.split('/')[-1]
branch = branch.split('/')[-1]
try:
with API(token, 'gamunetwork/gamunetwork.github.io', simulate=simulate) as (api, path):
api.auto_clean = clean
reports_path = f"{path}/docs/reports/{repository}/{branch}"
if os.path.exists(reports_path):
shutil.rmtree(reports_path)
os.makedirs(reports_path, exist_ok=True)
try:
shutil.copytree(test_reports_path, reports_path, dirs_exist_ok=True)
except FileExistsError:
info(f"Test reports already exist in {reports_path}, overwriting them")
except FileNotFoundError:
warning(f"Test reports not found in {test_reports_path}")
else:
info(f"Test reports copied to {reports_path}")
api.push(f"Updated test reports for {repository}/{branch}")
except Exception as e:
critical(str(e))
sys.exit(1)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Push test reports to repository')
parser.add_argument('token', help='GitHub api token')
parser.add_argument('repository', help='Repository name')
parser.add_argument('branch', help='Branch name')
parser.add_argument('test_reports_path', help='Test reports path')
parser.add_argument('-s', '--simulate', action='store_true', help='simulate the process without pushing to repository')
parser.add_argument('-nc', '--no-clean', action='store_true', help='do not delete the cloned repository after the process is done')
debug_group = parser.add_argument_group('Debugging options')
debug_group_mode = debug_group.add_mutually_exclusive_group()
debug_group_mode.add_argument('-d', '--debug', action='store_true', help='enable debug mode (show debug messages)')
debug_group_mode.add_argument('-dd', '--deep-debug', action='store_true', help='enable deep debug mode (show deep debug messages)')
debug_group_mode.add_argument('-q', '--quiet', action='store_true', help='enable quiet mode (show only error messages)')
debug_group_sensitive = debug_group.add_mutually_exclusive_group()
debug_group_sensitive.add_argument('--show-sensitive', action='store_true', help='allow showing sensitive information in logs')
debug_group_sensitive.add_argument('--show-encoded', action='store_true', help='show encoded sensitive information in logs')
args = parser.parse_args()
if args.debug:
Printer().set_level(Printer.LEVELS.DEBUG)
elif args.deep_debug:
Printer().set_level(Printer.LEVELS.DEEP_DEBUG)
elif args.quiet:
Printer().set_level(Printer.LEVELS.ERROR)
if args.show_sensitive:
Printer().show_sensitive(Printer.SENSITIVE_LEVELS.SHOW)
elif args.show_encoded:
Printer().show_sensitive(Printer.SENSITIVE_LEVELS.ENCODE)
main(args.token, args.repository, args.branch, args.test_reports_path, args.simulate, not args.no_clean)