@@ -25,33 +25,37 @@ class StatusResult(TypedDict):
25
25
included_helper_text : dict [str , str ]
26
26
27
27
28
- CUSTOM_TARGET_TEXT_PATCH_KEY = "custom_target_helper_text_patch"
29
- CUSTOM_TARGET_TEXT_PROJECT_KEY = "custom_target_helper_text_project"
30
- CUSTOM_RCB_INDIRECT_CHANGES_KEY = "custom_rcb_indirect_changes_helper_text"
31
- CUSTOM_RCB_ADJUST_BASE_KEY = "custom_rcb_adjust_base_helper_text"
32
- CUSTOM_TARGET_TEXT_VALUE = (
33
- "Your {context} {notification_type} has failed because the {point_of_comparison} coverage ({coverage}%) is below the target coverage ({target}%). "
34
- "You can increase the {point_of_comparison} coverage or adjust the "
35
- "[target](https://docs.codecov.com/docs/commit-status#target) coverage."
36
- )
37
- CUSTOM_RCB_INDIRECT_CHANGES_VALUE = (
38
- "Your {context} {notification_type} has failed because you have indirect coverage changes. "
39
- "Learn more about [Unexpected Coverage Changes](https://docs.codecov.com/docs/unexpected-coverage-changes) "
40
- "and [reasons for indirect coverage changes](https://docs.codecov.com/docs/unexpected-coverage-changes#reasons-for-indirect-changes)."
41
- )
42
- CUSTOM_RCB_TEXT_VALUE = (
43
- "Your project {notification_type} has failed because the head coverage ({coverage}%) "
44
- "is below the [adjusted base coverage](https://docs.codecov.com/docs/removed-code-behavior#option-3-default-adjust_base) ({adjusted_base_cov}%). "
45
- "You can increase the head coverage or adjust the "
46
- "[Removed Code Behavior](https://docs.codecov.com/docs/removed-code-behavior)."
47
- )
28
+ class HelperTextKey (str , Enum ):
29
+ CUSTOM_TARGET_PATCH = "custom_target_helper_text_patch"
30
+ CUSTOM_TARGET_PROJECT = "custom_target_helper_text_project"
31
+ RCB_INDIRECT_CHANGES = "rcb_indirect_changes_helper_text"
32
+ RCB_ADJUST_BASE = "rcb_adjust_base_helper_text"
33
+
34
+
35
+ class HelperTextTemplate (str , Enum ):
36
+ CUSTOM_TARGET = (
37
+ "Your {context} {notification_type} has failed because the {point_of_comparison} coverage ({coverage}%) is below the target coverage ({target}%). "
38
+ "You can increase the {point_of_comparison} coverage or adjust the "
39
+ "[target](https://docs.codecov.com/docs/commit-status#target) coverage."
40
+ )
41
+ INDIRECT_CHANGES = (
42
+ "Your {context} {notification_type} has failed because you have indirect coverage changes. "
43
+ "Learn more about [Unexpected Coverage Changes](https://docs.codecov.com/docs/unexpected-coverage-changes) "
44
+ "and [reasons for indirect coverage changes](https://docs.codecov.com/docs/unexpected-coverage-changes#reasons-for-indirect-changes)."
45
+ )
46
+ RCB_ADJUST_BASE = (
47
+ "Your project {notification_type} has failed because the head coverage ({coverage}%) "
48
+ "is below the [adjusted base coverage](https://docs.codecov.com/docs/removed-code-behavior#option-3-default-adjust_base) ({adjusted_base_cov}%). "
49
+ "You can increase the head coverage or adjust the "
50
+ "[Removed Code Behavior](https://docs.codecov.com/docs/removed-code-behavior)."
51
+ )
48
52
49
53
50
54
HELPER_TEXT_MAP = {
51
- CUSTOM_TARGET_TEXT_PATCH_KEY : CUSTOM_TARGET_TEXT_VALUE ,
52
- CUSTOM_TARGET_TEXT_PROJECT_KEY : CUSTOM_TARGET_TEXT_VALUE ,
53
- CUSTOM_RCB_INDIRECT_CHANGES_KEY : CUSTOM_RCB_INDIRECT_CHANGES_VALUE ,
54
- CUSTOM_RCB_ADJUST_BASE_KEY : CUSTOM_RCB_TEXT_VALUE ,
55
+ HelperTextKey . CUSTOM_TARGET_PATCH : HelperTextTemplate . CUSTOM_TARGET ,
56
+ HelperTextKey . CUSTOM_TARGET_PROJECT : HelperTextTemplate . CUSTOM_TARGET ,
57
+ HelperTextKey . RCB_INDIRECT_CHANGES : HelperTextTemplate . INDIRECT_CHANGES ,
58
+ HelperTextKey . RCB_ADJUST_BASE : HelperTextTemplate . RCB_ADJUST_BASE ,
55
59
}
56
60
57
61
@@ -130,14 +134,18 @@ def get_patch_status(
130
134
f"{ coverage_rounded } % of diff hit (target { target_rounded } %)"
131
135
)
132
136
if state == StatusState .failure .value and is_custom_target :
133
- helper_text = HELPER_TEXT_MAP [CUSTOM_TARGET_TEXT_PATCH_KEY ].format (
137
+ helper_text = HELPER_TEXT_MAP [
138
+ HelperTextKey .CUSTOM_TARGET_PATCH
139
+ ].value .format (
134
140
context = self .context ,
135
141
notification_type = notification_type ,
136
142
point_of_comparison = self .context ,
137
143
coverage = coverage_rounded ,
138
144
target = target_rounded ,
139
145
)
140
- included_helper_text [CUSTOM_TARGET_TEXT_PATCH_KEY ] = helper_text
146
+ included_helper_text [HelperTextKey .CUSTOM_TARGET_PATCH .value ] = (
147
+ helper_text
148
+ )
141
149
return StatusResult (
142
150
state = state , message = message , included_helper_text = included_helper_text
143
151
)
@@ -334,9 +342,9 @@ def _apply_adjust_base_behavior(
334
342
coverage_rounded = round_number (self .current_yaml , head_coverage )
335
343
336
344
# their comparison failed despite the adjusted base, give them helper text about it
337
- helper_text [CUSTOM_RCB_ADJUST_BASE_KEY ] = HELPER_TEXT_MAP [
338
- CUSTOM_RCB_ADJUST_BASE_KEY
339
- ].format (
345
+ helper_text [HelperTextKey . RCB_ADJUST_BASE . value ] = HELPER_TEXT_MAP [
346
+ HelperTextKey . RCB_ADJUST_BASE
347
+ ].value . format (
340
348
notification_type = notification_type ,
341
349
coverage = coverage_rounded ,
342
350
adjusted_base_cov = rounded_base_adjusted_coverage ,
@@ -370,8 +378,8 @@ def _apply_fully_covered_patch_behavior(
370
378
)
371
379
372
380
# their comparison failed because of unexpected/indirect changes, give them helper text about it
373
- helper_text [CUSTOM_RCB_INDIRECT_CHANGES_KEY ] = HELPER_TEXT_MAP [
374
- CUSTOM_RCB_INDIRECT_CHANGES_KEY
381
+ helper_text [HelperTextKey . RCB_INDIRECT_CHANGES ] = HELPER_TEXT_MAP [
382
+ HelperTextKey . RCB_INDIRECT_CHANGES
375
383
].format (
376
384
context = self .context ,
377
385
notification_type = notification_type ,
@@ -550,14 +558,16 @@ def _get_project_status(
550
558
target_rounded = round_number (self .current_yaml , target_coverage )
551
559
message = f"{ head_coverage_rounded } % (target { target_rounded } %)"
552
560
if state == StatusState .failure .value :
553
- helper_text = HELPER_TEXT_MAP [CUSTOM_TARGET_TEXT_PROJECT_KEY ].format (
561
+ helper_text = HELPER_TEXT_MAP [
562
+ HelperTextKey .CUSTOM_TARGET_PROJECT
563
+ ].value .format (
554
564
context = self .context ,
555
565
notification_type = notification_type ,
556
566
point_of_comparison = self .point_of_comparison ,
557
567
coverage = head_coverage_rounded ,
558
568
target = target_rounded ,
559
569
)
560
- included_helper_text [CUSTOM_TARGET_TEXT_PROJECT_KEY ] = helper_text
570
+ included_helper_text [HelperTextKey . CUSTOM_TARGET_PROJECT ] = helper_text
561
571
return StatusResult (
562
572
state = state , message = message , included_helper_text = included_helper_text
563
573
)
0 commit comments