-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalerts_slack_fmt.py
More file actions
139 lines (119 loc) · 4.35 KB
/
alerts_slack_fmt.py
File metadata and controls
139 lines (119 loc) · 4.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from textwrap import dedent
from helpers import left_align_list
#
# SLACK Alert formatting
#
class SlackAlerts:
#
# PASS
#
PASS_TESTS = str(
"{:2s} *{:19s}*".format(str(":white_check_mark:"), str("VALID STYLES"))
)
# Fonts
VALID_FONT_TYPE = str(
"{:4s} {:4s} {:12}".format(
str(":ballot_box_with_check:"), str("VALID"), str("Font Type")
)
)
VALID_FONT_SIZE = str(
"{:4s} {:4s} {:13}".format(
str(":ballot_box_with_check:"), str("VALID"), str("Font Size")
)
)
VALID_FONT_COLOR = str(
"{:4s} {:4s} {:12}".format(
str(":ballot_box_with_check:"), str("VALID"), str("Font Color")
)
)
# Borders
VALID_BORDER_STYLE = str(" :ballot_box_with_check: " + "Border Style ")
VALID_BORDER_WIDTH = str(" :ballot_box_with_check: " + "Border Width ")
VALID_BORDER_COLOR = str(" :ballot_box_with_check: " + "Border Color ")
# Margins
VALID_MARGIN = str(" :ballot_box_with_check: " + "Margin ")
VALID_MARGIN_TOP = str(" :ballot_box_with_check: " + "Margin Top ")
VALID_MARGIN_BOTTOM = str(" :ballot_box_with_check: " + "Margin Bottom ")
VALID_PADDING = str(" :ballot_box_with_check: " + "Padding ")
# Background Color
VALID_BACKGROUND_COLOR = str(" :ballot_box_with_check: " + "BG Color ")
#
# FAIL
#
FAIL_TESTS = str("{:2s} *{:16s}*".format(str(":x:"), str("INVALID STYLES")))
# Fonts
INVALID_FONT_TYPE = str(
"{:4s} {:4s} {:12}".format(str(":warning:"), str("ALERT"), str("Font Type"))
)
INVALID_FONT_SIZE = str(
"{:4s} {:4s} {:12}".format(str(":warning:"), str("ALERT"), str("Font Size"))
)
INVALID_FONT_COLOR = str(
"{:4s} {:4s} {:12}".format(str(":warning:"), str("ALERT"), str("Font Color"))
)
# Borders
INVALID_BORDER_STYLE = str(" :warning: ALERT " + "Border Style ")
INVALID_BORDER_WIDTH = str(" :warning: ALERT " + "Border Width ")
INVALID_BORDER_COLOR = str(" :warning: ALERT " + "Border Color ")
# Margins
INVALID_MARGIN = str(" :warning: ALERT " + "Margin ")
INVALID_MARGIN_TOP = str(" :warning: ALERT " + "Margin Top ")
INVALID_MARGIN_BOTTOM = str(" :warning: ALERT " + "Margin Bottom ")
INVALID_PADDING = str(" :warning: ALERT " + "Padding ")
# Background Colors
INVALID_BACKGROUND_COLOR = str(" :warning: ALERT " + "BG Color ")
def slack_err_msg(invalid_count):
if invalid_count > 0:
return str(
f" {SlackAlerts.FAIL_TESTS} {invalid_count} styles need revision "
)
else:
return str(f"\n :white_check_mark: No invalid styles found in component ")
def slack_valid_msg(valid_count):
if valid_count > 0:
return str(f" {SlackAlerts.PASS_TESTS} {valid_count} valid styles found ")
else:
return str(f"\n :bangbang: No valid styles found in component ")
def slack_msg(alert, value, pos=None, valid=True, level=None, kind=None):
# If you do not wish to see the valid statements,
# you can comment this first "if valid" clause out.
if valid:
if "font-size" in kind:
return str(
" {} `{:16s}` found in _{}_ of {} ".format(
str(alert), str(value + "pt"), str(pos), str(level)
)
)
else:
return str(
" {} `{:16s}` found in _{}_ of {} ".format(
str(alert), str(value), str(pos), str(level)
)
)
if not valid:
if "font-size" in kind:
return str(
" {} `{:16s}` found in _{}_ of {} ".format(
str(alert), str(value + "pt"), str(pos), str(level)
)
)
else:
return str(
" {} `{:16s}` found in _{}_ of {} ".format(
str(alert), str(value), str(pos), str(level)
)
)
def fmt_slack_output(valid_styles=None, invalid_styles=None):
return dedent(
"""
{spacer}
{invalid}
{spacer}
{valid}
{spacer}
""".format(
spacer="\n",
invalid=left_align_list(invalid_styles) if invalid_styles else None,
valid=left_align_list(valid_styles) if valid_styles else None,
)
)