MCPcopy Create free account
hub / github.com/docker/docker-agent / hooksFor

Method hooksFor

pkg/hooks/executor.go:282–299  ·  view source on GitHub ↗

hooksFor returns the deduplicated list of hooks that should run for (event, toolName). Dedup by (type, command, args) catches the common case of an explicit YAML hook overlapping a runtime auto-injected one (e.g. WithAddDate plus a user-authored add_date entry).

(event EventType, toolName string)

Source from the content-addressed store, hash-verified

280// case of an explicit YAML hook overlapping a runtime auto-injected
281// one (e.g. WithAddDate plus a user-authored add_date entry).
282func (e *Executor) hooksFor(event EventType, toolName string) []Hook {
283 seen := make(map[string]bool)
284 var hooks []Hook
285 for _, m := range e.events[event] {
286 if !m.matches(toolName) {
287 continue
288 }
289 for _, h := range m.hooks {
290 key := dedupKey(h)
291 if seen[key] {
292 continue
293 }
294 seen[key] = true
295 hooks = append(hooks, h)
296 }
297 }
298 return hooks
299}
300
301// dedupKey returns a deterministic key identifying a hook by (type, command, args).
302func dedupKey(h Hook) string {

Callers 1

DispatchMethod · 0.95

Calls 2

dedupKeyFunction · 0.85
matchesMethod · 0.80

Tested by

no test coverage detected