-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.py
More file actions
54 lines (42 loc) · 1.35 KB
/
actions.py
File metadata and controls
54 lines (42 loc) · 1.35 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
import sys
from tabulate import tabulate
from lib.datetimeutils import *
from lib.consolecolors import colored_status
from api.runs import *
dispatch = {
'last': get_last_run,
'all': get_all_runs,
'status': get_repos_status
}
try:
command = sys.argv[1]
if command not in dispatch:
print(f"Command '{command}' is not defined.")
exit(1)
except IndexError:
raise SystemExit(f"Usage: {sys.argv[0]} <command> [command parameters]")
if len(sys.argv) > 2:
args = sys.argv[2:]
else:
args = []
response = dispatch[command](args)
headers = ['nr', 'repository', 'result', 'branch', 'commit', 'timestamp', 'duration', 'committer', 'message']
table_data = []
count = 1
for run in response:
message = run['head_commit']['message'].split('\n')[0]
timestamp = localized_timestamp(run['created_at'])
timestamp_end = localized_timestamp(run['updated_at'])
table_data.append([
count,
run['repository']['full_name'],
colored_status(run['conclusion'] if run['conclusion'] else run['status']),
run['head_branch'],
run['head_sha'][:7],
timestamp.strftime('%Y-%m-%d %H:%M:%S%z'),
timestamp_diff(run['created_at'], run['updated_at']),
run['head_commit']['author']['name'],
message
])
count += 1
print(tabulate(table_data, headers, tablefmt="grid"))