| 262 | } |
| 263 | |
| 264 | func selectAuditComparisonBaseline(current ProcessedRun, candidates []auditComparisonCandidate) *auditComparisonCandidate { |
| 265 | auditComparisonLog.Printf("Selecting baseline from %d candidates for run %d", len(candidates), current.Run.DatabaseID) |
| 266 | if len(candidates) == 0 { |
| 267 | return nil |
| 268 | } |
| 269 | |
| 270 | for index := range candidates { |
| 271 | scoreAuditComparisonCandidate(current, &candidates[index]) |
| 272 | } |
| 273 | |
| 274 | slices.SortStableFunc(candidates, func(left, right auditComparisonCandidate) int { |
| 275 | if left.Score != right.Score { |
| 276 | if left.Score > right.Score { |
| 277 | return -1 |
| 278 | } |
| 279 | return 1 |
| 280 | } |
| 281 | switch { |
| 282 | case left.Run.CreatedAt.After(right.Run.CreatedAt): |
| 283 | return -1 |
| 284 | case right.Run.CreatedAt.After(left.Run.CreatedAt): |
| 285 | return 1 |
| 286 | default: |
| 287 | return 0 |
| 288 | } |
| 289 | }) |
| 290 | |
| 291 | return &candidates[0] |
| 292 | } |
| 293 | |
| 294 | func sameAuditComparisonWorkflow(left WorkflowRun, right WorkflowRun) bool { |
| 295 | if left.WorkflowPath != "" && right.WorkflowPath != "" { |