Skip to content

Commit 722870f

Browse files
author
James Alseth
authored
Don't use a special case for message formatting based on policyID (#7)
1 parent 389db7f commit 722870f

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

.github/test/policy/always_warn.rego

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package always_warn
22

33
warn[msg] {
4-
msg := {
5-
"msg": "a warning! you should probably fix this",
6-
"details": {"policyID": "P0000"}
7-
}
8-
4+
msg := format_with_id("a warning! you should probably fix this", "P0000")
95
true
106
}
7+
8+
format_with_id(msg, id) = msg_fmt {
9+
msg_fmt := {
10+
"msg": sprintf("%s: %s", [id, msg]),
11+
"details": {"policyID": id}
12+
}
13+
}

main.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,30 +114,22 @@ func run() error {
114114
successes += len(result.Successes)
115115

116116
for _, fail := range result.Failures {
117-
// attempt to parse the policy ID section, skip if there are errors
117+
fails = append(fails, fmt.Sprintf("%s - %s", result.Filename, fail.Message))
118118
policyID, err := getPolicyIDFromMetadata(fail.Metadata, policyIDKey)
119119
if err != nil {
120-
fails = append(fails, fmt.Sprintf("%s - %s", result.Filename, fail.Message))
121120
continue
122121
}
123-
124-
fails = append(fails, fmt.Sprintf("%s - %s: %s", result.Filename, policyID, fail.Message))
125-
126122
if !contains(policiesWithFails, policyID) {
127123
policiesWithFails = append(policiesWithFails, policyID)
128124
}
129125
}
130126

131127
for _, warn := range result.Warnings {
132-
// attempt to parse the policy ID section, skip if there are errors
128+
warns = append(warns, fmt.Sprintf("%s - %s", result.Filename, warn.Message))
133129
policyID, err := getPolicyIDFromMetadata(warn.Metadata, policyIDKey)
134130
if err != nil {
135-
warns = append(warns, fmt.Sprintf("%s - %s", result.Filename, warn.Message))
136131
continue
137132
}
138-
139-
warns = append(warns, fmt.Sprintf("%s - %s: %s", result.Filename, policyID, warn.Message))
140-
141133
if !contains(policiesWithWarns, policyID) {
142134
policiesWithWarns = append(policiesWithWarns, policyID)
143135
}

0 commit comments

Comments
 (0)