Skip to content

Commit a12ab03

Browse files
committed
Resolve pipeline test error
1 parent 085657e commit a12ab03

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

.github/workflows/pull_request.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ jobs:
3535
files: '.github/test/resources'
3636
policy: '.github/test/policy/always_warn.rego'
3737
gh-token: ${{ secrets.GITHUB_TOKEN }}
38-
gh-comment-url: ${{ github.event.pull_request.comments_url }}

main.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,29 @@ type commentData struct {
3535
DocsURL string
3636
}
3737

38-
type jsonResult struct {
38+
// Result describes the result of a single rule evaluation.
39+
type Result struct {
3940
Message string `json:"msg"`
4041
Metadata map[string]interface{} `json:"metadata,omitempty"`
42+
Outputs []string `json:"outputs,omitempty"`
4143
}
4244

43-
type jsonCheckResult struct {
44-
Filename string `json:"filename"`
45-
Successes []jsonResult `json:"successes"`
46-
Warnings []jsonResult `json:"warnings,omitempty"`
47-
Failures []jsonResult `json:"failures,omitempty"`
45+
type CheckResult struct {
46+
FileName string `json:"filename"`
47+
Namespace string `json:"namespace"`
48+
Successes int `json:"successes"`
49+
Skipped []Result `json:"skipped,omitempty"`
50+
Warnings []Result `json:"warnings,omitempty"`
51+
Failures []Result `json:"failures,omitempty"`
52+
Exceptions []Result `json:"exceptions,omitempty"`
4853
}
4954

5055
type metricsSubmission struct {
51-
SourceID string `json:"sourceID"`
52-
Successes int `json:"successes,omitempty"`
53-
Warnings metricsSeverity `json:"warns,omitempty"`
54-
Failures metricsSeverity `json:"fails,omitempty"`
55-
Details []jsonCheckResult `json:"details,omitempty"`
56+
SourceID string `json:"sourceID"`
57+
Successes int `json:"successes,omitempty"`
58+
Warnings metricsSeverity `json:"warns,omitempty"`
59+
Failures metricsSeverity `json:"fails,omitempty"`
60+
Details []CheckResult `json:"details,omitempty"`
5661
}
5762

5863
type metricsSeverity struct {
@@ -111,10 +116,10 @@ func run() error {
111116
var fails, warns []string
112117
var successes int
113118
for _, result := range results {
114-
successes += len(result.Successes)
119+
successes += result.Successes
115120

116121
for _, fail := range result.Failures {
117-
fails = append(fails, fmt.Sprintf("%s - %s", result.Filename, fail.Message))
122+
fails = append(fails, fmt.Sprintf("%s - %s", result.FileName, fail.Message))
118123
policyID, err := getPolicyIDFromMetadata(fail.Metadata, policyIDKey)
119124
if err != nil {
120125
continue
@@ -125,7 +130,7 @@ func run() error {
125130
}
126131

127132
for _, warn := range result.Warnings {
128-
warns = append(warns, fmt.Sprintf("%s - %s", result.Filename, warn.Message))
133+
warns = append(warns, fmt.Sprintf("%s - %s", result.FileName, warn.Message))
129134
policyID, err := getPolicyIDFromMetadata(warn.Metadata, policyIDKey)
130135
if err != nil {
131136
continue
@@ -264,7 +269,7 @@ func runConftestPull(url string) error {
264269
return nil
265270
}
266271

267-
func runConftestTest() ([]jsonCheckResult, error) {
272+
func runConftestTest() ([]CheckResult, error) {
268273
args := []string{"test", "--no-color", "--output", "json"}
269274
flags := getFlagsFromEnv()
270275
args = append(args, flags...)
@@ -274,9 +279,9 @@ func runConftestTest() ([]jsonCheckResult, error) {
274279
cmd := exec.Command("conftest", args...)
275280
out, _ := cmd.CombinedOutput() // intentionally ignore errors so we can parse the results
276281

277-
var results []jsonCheckResult
282+
var results []CheckResult
278283
if err := json.Unmarshal(out, &results); err != nil {
279-
return nil, fmt.Errorf("%s", string(out))
284+
return nil, fmt.Errorf("%s -- error is: %v", string(out), err)
280285
}
281286

282287
return results, nil

0 commit comments

Comments
 (0)