@@ -17,29 +17,26 @@ def get_updated_rule_data(rule: Rule) -> dict[str, Any]:
17
17
18
18
19
19
def check_value_changed (
20
- rule_data : dict [str , Any ], rule_data_before : dict [str , Any ], key : str , word : str
21
- ) -> str :
22
- if rule_data .get (key ) != rule_data_before .get (key ):
23
- old_value = rule_data_before .get (key )
24
- new_value = rule_data .get (key )
20
+ present_state : dict [str , Any ], prior_state : dict [str , Any ], key : str , word : str
21
+ ) -> str | None :
22
+ if present_state .get (key ) != prior_state .get (key ):
23
+ old_value = prior_state .get (key )
24
+ new_value = present_state .get (key )
25
25
return f"Changed { word } from *{ old_value } * to *{ new_value } *"
26
- return ""
27
26
28
27
29
- def check_added_or_removed (
30
- rule_data_after : dict [str , Any ],
31
- rule_data_before : dict [str , Any ],
28
+ def generate_diff_labels (
29
+ present_state : dict [str , Any ],
30
+ prior_state : dict [str , Any ],
32
31
rule : Rule ,
33
32
changed_data : DefaultDict [str , list [str ]],
34
33
key : str ,
35
- rule_section_type : str ,
36
- added : bool ,
34
+ statement : str ,
37
35
) -> DefaultDict [str , list [str ]]:
38
- verb = "Added" if added else "Removed"
39
- for data in rule_data_before .get (key , []):
40
- if data not in rule_data_after .get (key , []):
36
+ for data in prior_state .get (key , []):
37
+ if data not in present_state .get (key , []):
41
38
label = generate_rule_label (rule .project , rule , data )
42
- changed_data [data ["id" ]].append (f" { verb } { rule_section_type } ' { label } '" )
39
+ changed_data [data ["id" ]].append (statement . format ( label ) )
43
40
44
41
return changed_data
45
42
@@ -51,17 +48,17 @@ def get_changed_data(
51
48
Generate a list per type of issue alert rule data of what changes occurred on edit.
52
49
"""
53
50
changed_data : DefaultDict [str , list [str ]] = defaultdict (list )
54
- changed_data = check_added_or_removed (
55
- rule_data_before , rule_data , rule , changed_data , "conditions" , "condition" , added = True
51
+ changed_data = generate_diff_labels (
52
+ rule_data_before , rule_data , rule , changed_data , "conditions" , "Added condition '{}'"
56
53
)
57
- changed_data = check_added_or_removed (
58
- rule_data , rule_data_before , rule , changed_data , "conditions" , "condition" , added = False
54
+ changed_data = generate_diff_labels (
55
+ rule_data , rule_data_before , rule , changed_data , "conditions" , "Removed condition '{}'"
59
56
)
60
- changed_data = check_added_or_removed (
61
- rule_data_before , rule_data , rule , changed_data , "actions" , "action" , added = True
57
+ changed_data = generate_diff_labels (
58
+ rule_data_before , rule_data , rule , changed_data , "actions" , "Added action '{}'"
62
59
)
63
- changed_data = check_added_or_removed (
64
- rule_data , rule_data_before , rule , changed_data , "actions" , "action" , added = False
60
+ changed_data = generate_diff_labels (
61
+ rule_data , rule_data_before , rule , changed_data , "actions" , "Removed action '{}'"
65
62
)
66
63
67
64
frequency_text = check_value_changed (rule_data , rule_data_before , "frequency" , "frequency" )
0 commit comments