@@ -193,6 +193,7 @@ func PrintTests(
193193 w io.Writer ,
194194 tests []TestResult ,
195195 maxPassRatio float64 ,
196+ includeCodeOwners bool , // Include code owners in the output. Set to true if test results have code owners
196197) (runs , passes , fails , skips , panickedTests , racedTests , flakyTests int ) {
197198 p := message .NewPrinter (language .English ) // For formatting numbers
198199 sortTestResults (tests )
@@ -210,19 +211,17 @@ func PrintTests(
210211 "**Package**" ,
211212 "**Package Panicked?**" ,
212213 "**Avg Duration**" ,
213- "**Code Owners**" ,
214+ }
215+
216+ if includeCodeOwners {
217+ headers = append (headers , "**Code Owners**" )
214218 }
215219
216220 // Build test rows and summary data
217221 rows := [][]string {}
218222 for _ , test := range tests {
219223 if test .PassRatio < maxPassRatio {
220- owners := "Unknown"
221- if len (test .CodeOwners ) > 0 {
222- owners = strings .Join (test .CodeOwners , ", " )
223- }
224-
225- rows = append (rows , []string {
224+ row := []string {
226225 test .TestName ,
227226 fmt .Sprintf ("%.2f%%" , test .PassRatio * 100 ),
228227 fmt .Sprintf ("%t" , test .Panic ),
@@ -235,8 +234,17 @@ func PrintTests(
235234 test .TestPackage ,
236235 fmt .Sprintf ("%t" , test .PackagePanic ),
237236 avgDuration (test .Durations ).String (),
238- owners ,
239- })
237+ }
238+
239+ if includeCodeOwners {
240+ owners := "Unknown"
241+ if len (test .CodeOwners ) > 0 {
242+ owners = strings .Join (test .CodeOwners , ", " )
243+ }
244+ row = append (row , owners )
245+ }
246+
247+ rows = append (rows , row )
240248 }
241249
242250 runs += test .Runs
@@ -350,7 +358,7 @@ func PrintTests(
350358}
351359
352360// MarkdownSummary builds a summary of test results in markdown format, handy for reporting in CI and Slack
353- func MarkdownSummary (w io.Writer , testReport * TestReport , maxPassRatio float64 ) {
361+ func MarkdownSummary (w io.Writer , testReport * TestReport , maxPassRatio float64 , includeCodeOwners bool ) {
354362 var (
355363 avgPassRatio = 1.0
356364 testsData = bytes .NewBuffer (nil )
@@ -401,7 +409,7 @@ func MarkdownSummary(w io.Writer, testReport *TestReport, maxPassRatio float64)
401409 return
402410 }
403411
404- allRuns , passes , _ , _ , _ , _ , _ := PrintTests (testsData , tests , maxPassRatio )
412+ allRuns , passes , _ , _ , _ , _ , _ := PrintTests (testsData , tests , maxPassRatio , includeCodeOwners )
405413 if allRuns > 0 {
406414 avgPassRatio = float64 (passes ) / float64 (allRuns )
407415 }
@@ -414,7 +422,7 @@ func MarkdownSummary(w io.Writer, testReport *TestReport, maxPassRatio float64)
414422}
415423
416424// Helper function to save filtered results and logs to specified paths
417- func SaveFilteredResultsAndLogs (outputResultsPath , outputLogsPath string , report * TestReport ) error {
425+ func SaveFilteredResultsAndLogs (outputResultsPath , outputLogsPath string , report * TestReport , includeCodeOwners bool ) error {
418426 if outputResultsPath != "" {
419427 if err := os .MkdirAll (filepath .Dir (outputResultsPath ), 0755 ); err != nil { //nolint:gosec
420428 return fmt .Errorf ("error creating output directory: %w" , err )
@@ -430,7 +438,7 @@ func SaveFilteredResultsAndLogs(outputResultsPath, outputLogsPath string, report
430438 return fmt .Errorf ("error creating markdown file: %w" , err )
431439 }
432440 defer summaryFile .Close ()
433- MarkdownSummary (summaryFile , report , 1.0 )
441+ MarkdownSummary (summaryFile , report , 1.0 , includeCodeOwners )
434442 fmt .Printf ("Test results saved to %s and summary to %s\n " , jsonFileName , mdFileName )
435443 } else {
436444 fmt .Println ("No failed tests found based on the specified threshold and min pass ratio." )
0 commit comments