Skip to content

Commit 5006ea8

Browse files
Add back TypeMeta which is mandatory for scorecard object because it is used to distinguish the versions (v1alpha1 and v1alpha2) (#2159)
1 parent 5a677b4 commit 5006ea8

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

internal/scorecard/helpers/helpers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ func CalculateResult(tests []scapiv1alpha1.ScorecardTestResult) scapiv1alpha1.Sc
8888
// TestSuitesToScorecardOutput takes an array of test suites and generates a v1alpha1 ScorecardOutput object with the
8989
// provided suites and log
9090
func TestSuitesToScorecardOutput(suites []TestSuite, log string) scapiv1alpha1.ScorecardOutput {
91-
test := scapiv1alpha1.ScorecardOutput{
92-
Log: log,
93-
}
91+
test := scapiv1alpha1.NewScorecardOutput()
92+
test.Log = log
93+
9494
scorecardSuiteResults := []scapiv1alpha1.ScorecardSuiteResult{}
9595
for _, suite := range suites {
9696
results := []scapiv1alpha1.ScorecardTestResult{}
@@ -105,7 +105,7 @@ func TestSuitesToScorecardOutput(suites []TestSuite, log string) scapiv1alpha1.S
105105
scorecardSuiteResults = append(scorecardSuiteResults, scorecardSuiteResult)
106106
}
107107
test.Results = scorecardSuiteResults
108-
return test
108+
return *test
109109
}
110110

111111
// TestResultToScorecardTestResult is a helper function for converting from the TestResult type to the ScorecardTestResult type

pkg/apis/scorecard/v1alpha1/types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ type ScorecardOutputList struct {
105105
Items []ScorecardOutput `json:"items"`
106106
}
107107

108+
func NewScorecardOutput() *ScorecardOutput {
109+
return &ScorecardOutput{
110+
// The TypeMeta is mandatory because it is used to distinguish the versions (v1alpha1 and v1alpha2)
111+
TypeMeta: metav1.TypeMeta{
112+
Kind: "ScorecardOutput",
113+
APIVersion: "osdk.openshift.io/v1alpha1",
114+
},
115+
}
116+
}
117+
108118
func init() {
109119
SchemeBuilder.Register(&ScorecardOutput{}, &ScorecardOutputList{})
110120
}

pkg/apis/scorecard/v1alpha2/types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ type ScorecardOutput struct {
6464
Results []ScorecardTestResult `json:"results"`
6565
}
6666

67+
func NewScorecardOutput() *ScorecardOutput {
68+
return &ScorecardOutput{
69+
// The TypeMeta is mandatory because it is used to distinguish the versions (v1alpha1 and v1alpha2)
70+
TypeMeta: metav1.TypeMeta{
71+
Kind: "ScorecardOutput",
72+
APIVersion: "osdk.openshift.io/v1alpha2",
73+
},
74+
}
75+
}
76+
6777
func init() {
6878
SchemeBuilder.Register(&ScorecardOutput{})
6979
}

pkg/apis/scorecard/v1v2conversions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
func ConvertScorecardOutputV1ToV2(v1ScorecardOutput scapiv1alpha1.ScorecardOutput) scapiv1alpha2.ScorecardOutput {
2323

24-
output := scapiv1alpha2.ScorecardOutput{}
24+
output := scapiv1alpha2.NewScorecardOutput()
2525

2626
// convert v1 suite into v2 test results
2727
output.Results = make([]scapiv1alpha2.ScorecardTestResult, 0)
@@ -31,7 +31,7 @@ func ConvertScorecardOutputV1ToV2(v1ScorecardOutput scapiv1alpha1.ScorecardOutpu
3131
}
3232
output.Log = v1ScorecardOutput.Log
3333

34-
return output
34+
return *output
3535
}
3636

3737
func ConvertSuiteResultV1ToV2TestResults(v1SuiteResult scapiv1alpha1.ScorecardSuiteResult) []scapiv1alpha2.ScorecardTestResult {

0 commit comments

Comments
 (0)