-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolor.py
More file actions
95 lines (74 loc) · 1.55 KB
/
Copy pathcolor.py
File metadata and controls
95 lines (74 loc) · 1.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from kamidana import (
as_filter,
as_global,
)
from jinja2 import pass_context
from colour import Color
import os
success_texts = [
"success",
"succeeded",
"pass",
"passed",
"ok",
]
failure_texts = [
"failure",
"failed",
"fail",
"error",
"errored",
"ng",
]
@as_filter
@pass_context
def is_success(ctx, v):
if isinstance(v, str):
return v.lower() in success_texts
if v:
return True
return False
@as_filter
@pass_context
def is_failure(ctx, v):
if isinstance(v, str):
return v.lower() in failure_texts
if v:
return True
return False
@as_global
def status_success_color():
return Color(os.getenv('KAMIDANA_STATUS_SUCCESS', '#1f883d'))
@as_global
def status_failure_color():
return Color(os.getenv('KAMIDANA_STATUS_FAILURE', '#cf222e'))
@as_global
def status_other_color():
return Color(os.getenv('KAMIDANA_STATUS_OTHER', '#6e7781'))
@as_filter
@pass_context
def actions_status_color(ctx, v):
lower_v = v.lower()
if lower_v == 'success':
return status_success_color()
if lower_v == 'failure':
return status_failure_color()
return status_other_color()
@as_filter
@pass_context
def outcome_color(ctx, v):
return actions_status_color(ctx, v)
@as_filter
@pass_context
def status_color(ctx, v):
if is_success(ctx, v):
return status_success_color()
if is_failure(ctx, v):
return status_failure_color()
return status_other_color()
@as_filter
@pass_context
def discord_color(ctx, v):
html_color = Color(v).hex_l
hex_color = html_color.lstrip('#')
return int(hex_color, 16)