-
Notifications
You must be signed in to change notification settings - Fork 59
Include enforcement date in warnings for future effective_on violations #3412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -996,7 +996,10 @@ func (f *LegacyPostEvaluationFilter) CategorizeResults( | |
| warnings = append(warnings, result) | ||
| } | ||
| case "failure": | ||
| if getSeverity(result) == severityWarning || !isResultEffective(result, effectiveTime) { | ||
| if getSeverity(result) == severityWarning { | ||
| warnings = append(warnings, result) | ||
| } else if !isResultEffective(result, effectiveTime) { | ||
| result.Message = formatFutureEnforcementMessage(result) | ||
| warnings = append(warnings, result) | ||
| } else { | ||
| failures = append(failures, result) | ||
|
|
@@ -1119,7 +1122,10 @@ func (f *UnifiedPostEvaluationFilter) CategorizeResults( | |
| warnings = append(warnings, filteredResult) | ||
| } | ||
| case "failure": | ||
| if getSeverity(filteredResult) == severityWarning || !isResultEffective(filteredResult, effectiveTime) { | ||
| if getSeverity(filteredResult) == severityWarning { | ||
| warnings = append(warnings, filteredResult) | ||
| } else if !isResultEffective(filteredResult, effectiveTime) { | ||
| filteredResult.Message = formatFutureEnforcementMessage(filteredResult) | ||
| warnings = append(warnings, filteredResult) | ||
| } else { | ||
| failures = append(failures, filteredResult) | ||
|
|
@@ -1204,3 +1210,21 @@ func (f *UnifiedPostEvaluationFilter) determineOriginalType(filteredResult Resul | |
|
|
||
| return "unknown" | ||
| } | ||
|
|
||
| // formatFutureEnforcementMessage enhances a result message to indicate when | ||
| // a future effective_on date will cause enforcement to begin. | ||
| // Returns the enhanced message if effective_on is present, otherwise returns | ||
| // the original message unchanged. | ||
| func formatFutureEnforcementMessage(result Result) string { | ||
| originalMessage := result.Message | ||
|
|
||
| // Check if this result has an effective_on date | ||
| effectiveOnStr, ok := result.Metadata[metadataEffectiveOn].(string) | ||
| if !ok || effectiveOnStr == "" { | ||
| return originalMessage | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [low] correctness strings.TrimRight(originalMessage, ".") removes all trailing characters in the cutset, not just a single trailing period. If a message ends with "..." (ellipsis), all three dots are stripped. strings.TrimSuffix would be more precise. Suggested fix: Replace strings.TrimRight(originalMessage, ".") with strings.TrimSuffix(originalMessage, ".") to remove exactly one trailing period.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
|
|
||
| // Append enforcement notice with the effective_on date as-is | ||
| return fmt.Sprintf("%s. This will become a failure starting on %s", | ||
| strings.TrimSuffix(originalMessage, "."), effectiveOnStr) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[low] correctness
Shallow copy via 'enhancedResult := result' shares the underlying Metadata map between original and copy. Currently safe (only Message is modified), but could lead to subtle aliasing bugs if future changes also mutate Metadata on the enhanced result.