MCPcopy Create free account
hub / github.com/cli/cli / eliminateDuplicates

Function eliminateDuplicates

pkg/cmd/pr/checks/aggregate.go:96–120  ·  view source on GitHub ↗

eliminateDuplicates filters a set of checks to only the most recent ones if the set includes repeated runs

(checkContexts []api.CheckContext)

Source from the content-addressed store, hash-verified

94
95// eliminateDuplicates filters a set of checks to only the most recent ones if the set includes repeated runs
96func 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}

Callers 2

TestEliminateDuplicatesFunction · 0.85
aggregateChecksFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestEliminateDuplicatesFunction · 0.68