eliminateDuplicates filters a set of checks to only the most recent ones if the set includes repeated runs
(checkContexts []api.CheckContext)
| 94 | |
| 95 | // eliminateDuplicates filters a set of checks to only the most recent ones if the set includes repeated runs |
| 96 | func eliminateDuplicates(checkContexts []api.CheckContext) []api.CheckContext { |
| 97 | sort.Slice(checkContexts, func(i, j int) bool { return checkContexts[i].StartedAt.After(checkContexts[j].StartedAt) }) |
| 98 | |
| 99 | mapChecks := make(map[string]struct{}) |
| 100 | mapContexts := make(map[string]struct{}) |
| 101 | unique := make([]api.CheckContext, 0, len(checkContexts)) |
| 102 | |
| 103 | for _, ctx := range checkContexts { |
| 104 | if ctx.Context != "" { |
| 105 | if _, exists := mapContexts[ctx.Context]; exists { |
| 106 | continue |
| 107 | } |
| 108 | mapContexts[ctx.Context] = struct{}{} |
| 109 | } else { |
| 110 | key := fmt.Sprintf("%s/%s/%s", ctx.Name, ctx.CheckSuite.WorkflowRun.Workflow.Name, ctx.CheckSuite.WorkflowRun.Event) |
| 111 | if _, exists := mapChecks[key]; exists { |
| 112 | continue |
| 113 | } |
| 114 | mapChecks[key] = struct{}{} |
| 115 | } |
| 116 | unique = append(unique, ctx) |
| 117 | } |
| 118 | |
| 119 | return unique |
| 120 | } |
no outgoing calls