@@ -51,6 +51,8 @@ type aggregateOptions struct {
5151 baseSha string
5252 headSha string
5353 repoURL string
54+ repoPath string
55+ codeownersPath string
5456 gitHubWorkflowName string
5557 gitHubWorkflowRunURL string
5658}
@@ -101,6 +103,18 @@ func WithRepoURL(repoURL string) AggregateOption {
101103 }
102104}
103105
106+ func WithRepoPath (repoPath string ) AggregateOption {
107+ return func (opts * aggregateOptions ) {
108+ opts .repoURL = repoPath
109+ }
110+ }
111+
112+ func WithCodeOwnersPath (codeOwnersPath string ) AggregateOption {
113+ return func (opts * aggregateOptions ) {
114+ opts .codeownersPath = codeOwnersPath
115+ }
116+ }
117+
104118// WithGitHubWorkflowName sets the GitHub workflow name for the aggregated report.
105119func WithGitHubWorkflowName (githubWorkflowName string ) AggregateOption {
106120 return func (opts * aggregateOptions ) {
@@ -176,6 +190,28 @@ func LoadAndAggregate(resultsPath string, options ...AggregateOption) (*TestRepo
176190 return nil , fmt .Errorf ("error aggregating reports: %w" , err )
177191 }
178192
193+ // Map test results to test paths
194+ err = MapTestResultsToPaths (aggregatedReport , opts .repoPath )
195+ if err != nil {
196+ return nil , fmt .Errorf ("error mapping test results to paths: %w" , err )
197+ }
198+
199+ // Map test results to code owners if codeOwnersPath is provided
200+ if opts .codeownersPath != "" {
201+ err := MapTestResultsToOwners (aggregatedReport , opts .codeownersPath )
202+ if err != nil {
203+ return nil , fmt .Errorf ("error mapping test results to code owners: %w" , err )
204+ }
205+ }
206+
207+ sendToSplunk := opts .splunkURL != ""
208+ if sendToSplunk {
209+ err = sendDataToSplunk (& opts , * aggregatedReport )
210+ if err != nil {
211+ return aggregatedReport , fmt .Errorf ("error sending data to Splunk: %w" , err )
212+ }
213+ }
214+
179215 return aggregatedReport , nil
180216}
181217
@@ -444,7 +480,6 @@ func aggregate(reportChan <-chan *TestReport, errChan <-chan error, opts *aggreg
444480 testMap = make (map [string ]TestResult )
445481 excludedTests = map [string ]struct {}{}
446482 selectedTests = map [string ]struct {}{}
447- sendToSplunk = opts .splunkURL != ""
448483 )
449484
450485 for report := range reportChan {
@@ -497,12 +532,6 @@ func aggregate(reportChan <-chan *TestReport, errChan <-chan error, opts *aggreg
497532 fullReport .Results = aggregatedResults
498533 fullReport .GenerateSummaryData ()
499534
500- if sendToSplunk {
501- err = sendDataToSplunk (opts , * fullReport )
502- if err != nil {
503- return fullReport , fmt .Errorf ("error sending data to Splunk: %w" , err )
504- }
505- }
506535 return fullReport , err
507536}
508537
@@ -633,6 +662,7 @@ func sendDataToSplunk(opts *aggregateOptions, report TestReport) error {
633662 }
634663 log .Info ().Msgf ("Example Run. See '%s' for the results that would be sent to splunk" , exampleSplunkReportFileName )
635664 } else {
665+ fmt .Printf ("Final sent: %v" , reportData )
636666 resp , err := client .R ().SetBody (reportData ).Post ("" )
637667 if err != nil {
638668 splunkErrs = append (splunkErrs , fmt .Errorf ("error sending report '%s' to Splunk: %w" , report .ID , err ))
@@ -680,6 +710,8 @@ func batchSplunkResults(results []SplunkTestResult) (batchData bytes.Buffer, res
680710 }
681711 resultTestNames = append (resultTestNames , result .Event .Data .TestName )
682712 }
713+ fmt .Println ("Formatted Batch Data:" )
714+ fmt .Println (batchData .String ())
683715 return batchData , resultTestNames , nil
684716}
685717
0 commit comments