@@ -19,7 +19,11 @@ import (
19
19
"github.com/arduino/go-paths-helper"
20
20
)
21
21
22
- type reportType struct {
22
+ // Report is the global instance of the check results ReportType struct
23
+ var Report ReportType
24
+
25
+ // ReportType is the type for the check results report
26
+ type ReportType struct {
23
27
Configuration toolConfigurationReportType `json:"configuration"`
24
28
Projects []projectReportType `json:"projects"`
25
29
Summary summaryReportType `json:"summary"`
@@ -63,10 +67,8 @@ type summaryReportType struct {
63
67
ErrorCount int `json:"errorCount"`
64
68
}
65
69
66
- var report reportType
67
-
68
70
// Initialize adds the tool configuration data to the report.
69
- func Initialize () {
71
+ func ( report * ReportType ) Initialize () {
70
72
report .Configuration = toolConfigurationReportType {
71
73
Paths : []* paths.Path {configuration .TargetPath ()},
72
74
ProjectType : configuration .SuperprojectTypeFilter ().String (),
@@ -75,7 +77,7 @@ func Initialize() {
75
77
}
76
78
77
79
// Record records the result of a check and returns a text summary for it.
78
- func Record (checkedProject project.Type , checkConfiguration checkconfigurations.Type , checkResult checkresult.Type , checkOutput string ) string {
80
+ func ( report * ReportType ) Record (checkedProject project.Type , checkConfiguration checkconfigurations.Type , checkResult checkresult.Type , checkOutput string ) string {
79
81
checkMessage := message (checkConfiguration .MessageTemplate , checkOutput )
80
82
81
83
checkLevel , err := checklevel .CheckLevel (checkConfiguration )
@@ -104,7 +106,7 @@ func Record(checkedProject project.Type, checkConfiguration checkconfigurations.
104
106
Message : checkMessage ,
105
107
}
106
108
107
- reportExists , projectReportIndex := getProjectReportIndex (checkedProject .Path )
109
+ reportExists , projectReportIndex := report . getProjectReportIndex (checkedProject .Path )
108
110
if ! reportExists {
109
111
// There is no existing report for this project.
110
112
report .Projects = append (
@@ -130,8 +132,8 @@ func Record(checkedProject project.Type, checkConfiguration checkconfigurations.
130
132
}
131
133
132
134
// AddProjectSummaryReport summarizes the results of all checks on the given project and adds it to the report.
133
- func AddProjectSummaryReport (checkedProject project.Type ) {
134
- reportExists , projectReportIndex := getProjectReportIndex (checkedProject .Path )
135
+ func ( report * ReportType ) AddProjectSummaryReport (checkedProject project.Type ) {
136
+ reportExists , projectReportIndex := report . getProjectReportIndex (checkedProject .Path )
135
137
if ! reportExists {
136
138
panic (fmt .Sprintf ("Unable to find report for %v when generating report summary" , checkedProject .Path ))
137
139
}
@@ -158,8 +160,8 @@ func AddProjectSummaryReport(checkedProject project.Type) {
158
160
}
159
161
160
162
// ProjectSummaryText returns a text summary of the check results for the given project.
161
- func ProjectSummaryText (checkedProject project.Type ) string {
162
- reportExists , projectReportIndex := getProjectReportIndex (checkedProject .Path )
163
+ func ( report ReportType ) ProjectSummaryText (checkedProject project.Type ) string {
164
+ reportExists , projectReportIndex := report . getProjectReportIndex (checkedProject .Path )
163
165
if ! reportExists {
164
166
panic (fmt .Sprintf ("Unable to find report for %v when generating report summary text" , checkedProject .Path ))
165
167
}
@@ -169,7 +171,7 @@ func ProjectSummaryText(checkedProject project.Type) string {
169
171
}
170
172
171
173
// AddSummaryReport summarizes the check results for all projects and adds it to the report.
172
- func AddSummaryReport () {
174
+ func ( report * ReportType ) AddSummaryReport () {
173
175
pass := true
174
176
warningCount := 0
175
177
errorCount := 0
@@ -189,16 +191,16 @@ func AddSummaryReport() {
189
191
}
190
192
191
193
// SummaryText returns a text summary of the cumulative check results.
192
- func SummaryText () string {
194
+ func ( report ReportType ) SummaryText () string {
193
195
return fmt .Sprintf ("Finished checking projects. Results:\n Warning count: %v\n Error count: %v\n Checks passed: %v\n " , report .Summary .WarningCount , report .Summary .ErrorCount , report .Summary .Pass )
194
196
}
195
197
196
198
// Report returns a JSON formatted report of checks on all projects.
197
- func JSONReport () string {
198
- return string (jsonReportRaw ())
199
+ func ( report ReportType ) JSONReport () string {
200
+ return string (report . jsonReportRaw ())
199
201
}
200
202
201
- func jsonReportRaw () []byte {
203
+ func ( report ReportType ) jsonReportRaw () []byte {
202
204
reportJSON , err := json .MarshalIndent (report , "" , " " )
203
205
if err != nil {
204
206
panic (fmt .Sprintf ("Error while formatting checks report: %v" , err ))
@@ -208,21 +210,21 @@ func jsonReportRaw() []byte {
208
210
}
209
211
210
212
// WriteReport writes a report for all projects to the specified file.
211
- func WriteReport () {
213
+ func ( report ReportType ) WriteReport () {
212
214
// Write report file
213
- err := configuration .ReportFilePath ().WriteFile (jsonReportRaw ())
215
+ err := configuration .ReportFilePath ().WriteFile (report . jsonReportRaw ())
214
216
if err != nil {
215
217
feedback .Errorf ("Error while writing report: %v" , err )
216
218
os .Exit (errorcodes .ErrGeneric )
217
219
}
218
220
}
219
221
220
222
// Passed returns whether the checks passed cumulatively.
221
- func Passed () bool {
223
+ func ( report ReportType ) Passed () bool {
222
224
return report .Summary .Pass
223
225
}
224
226
225
- func getProjectReportIndex (projectPath * paths.Path ) (bool , int ) {
227
+ func ( report ReportType ) getProjectReportIndex (projectPath * paths.Path ) (bool , int ) {
226
228
var index int
227
229
var projectReport projectReportType
228
230
for index , projectReport = range report .Projects {
0 commit comments