Skip to content

Commit 3ace1a7

Browse files
authored
Merge pull request #35 from srz-zumix/feature/status_to_boolean
2 parents bc0510a + 2eb891a commit 3ace1a7

5 files changed

Lines changed: 56 additions & 23 deletions

File tree

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ README.md: readme/README.md.j2 Makefile additionals/*.py entorypoint.sh
55

66
setup:
77
pip install -r requirements.txt
8+
9+
clean:
10+
rm -f README.md

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
* [reader](https://github.com/podhmo/kamidana/blob/master/kamidana/additionals/reader.py)
1212
* kamidana-action additonals
1313
* [color](additionals/color.py)
14+
* is_success
15+
* is_failure
1416
* (as_global) status_success_color
1517
* (as_global) status_failure_color
1618
* (as_global) status_other_color
17-
* outcome_color
19+
* actions_status_color
1820
* status_color
1921
* discord_color
2022
* [filter](additionals/filter.py)

additionals/color.py

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,44 @@
77
import os
88

99

10+
success_texts = [
11+
"success",
12+
"succeeded",
13+
"pass",
14+
"passed",
15+
"ok",
16+
]
17+
18+
failure_texts = [
19+
"failure",
20+
"failed",
21+
"fail",
22+
"error",
23+
"errored",
24+
"ng",
25+
]
26+
27+
28+
@as_filter
29+
@pass_context
30+
def is_success(ctx, v):
31+
if isinstance(v, str):
32+
return v.lower() in success_texts
33+
if v:
34+
return True
35+
return False
36+
37+
38+
@as_filter
39+
@pass_context
40+
def is_failure(ctx, v):
41+
if isinstance(v, str):
42+
return v.lower() in failure_texts
43+
if v:
44+
return True
45+
return False
46+
47+
1048
@as_global
1149
def status_success_color():
1250
return Color(os.getenv('KAMIDANA_STATUS_SUCCESS', '#1f883d'))
@@ -24,7 +62,7 @@ def status_other_color():
2462

2563
@as_filter
2664
@pass_context
27-
def outcome_color(ctx, v):
65+
def actions_status_color(ctx, v):
2866
lower_v = v.lower()
2967
if lower_v == 'success':
3068
return status_success_color()
@@ -33,31 +71,18 @@ def outcome_color(ctx, v):
3371
return status_other_color()
3472

3573

36-
success_texts = [
37-
"success",
38-
"succeeded",
39-
"pass",
40-
"passed",
41-
"ok",
42-
]
43-
44-
failure_texts = [
45-
"failure",
46-
"failed",
47-
"fail",
48-
"error",
49-
"errored",
50-
"ng",
51-
]
52-
74+
@as_filter
75+
@pass_context
76+
def outcome_color(ctx, v):
77+
return actions_status_color(ctx, v)
78+
5379

5480
@as_filter
5581
@pass_context
5682
def status_color(ctx, v):
57-
lower_v = v.lower()
58-
if lower_v in success_texts:
83+
if is_success(ctx, v):
5984
return status_success_color()
60-
if lower_v in failure_texts:
85+
if is_failure(ctx, v):
6186
return status_failure_color()
6287
return status_other_color()
6388

additionals/filter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ def json_query(ctx, v, query):
4545
@pass_context
4646
def typeof(ctx, v):
4747
return type(v)
48+

readme/README.md.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
* [reader](https://github.com/podhmo/kamidana/blob/master/kamidana/additionals/reader.py)
1212
* kamidana-action additonals
1313
* [color](additionals/color.py)
14+
* is_success
15+
* is_failure
1416
* (as_global) status_success_color
1517
* (as_global) status_failure_color
1618
* (as_global) status_other_color
17-
* outcome_color
19+
* actions_status_color
1820
* status_color
1921
* discord_color
2022
* [filter](additionals/filter.py)

0 commit comments

Comments
 (0)