Skip to content

refactor(hooks): simplify package while preserving features#2522

Merged
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/simplify-hooks-package-code-99feacb9
Apr 27, 2026
Merged

refactor(hooks): simplify package while preserving features#2522
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/simplify-hooks-package-code-99feacb9

Conversation

@dgageot
Copy link
Copy Markdown
Member

@dgageot dgageot commented Apr 27, 2026

Trim ~30% of non-test code in pkg/hooks while keeping every public API
and behavioral contract intact. All hooks tests, runtime hook-wiring
tests, go vet, and golangci-lint pass.

Changes

  • Unify the Executor event lookup: remove the eventHooks{flat, matchers} split and the selectHooks helper. Every event now compiles
    to a single []matcher slice; flat events become one matcher with an
    empty pattern, so dispatch is one filter loop.
  • Inline executeHooks + aggregateResults + dedup into Dispatch.
    The 5-return-value executeHook becomes runHook returning a
    hookResult. aggregate uses a clean switch over per-hook outcomes.
  • Replace the contextEvents switch with a small
    map[EventType]bool to decide which events route plain stdout into
    AdditionalContext.
  • Merge builtin.go into handler.go: registry, factories, and
    handlers now live in one file. HookTypeBuiltin moves into types.go
    alongside HookTypeCommand.
  • Compact Config.IsEmpty, convertHooks/convertMatchers, and the
    builtins Register (single map iteration). Extract a small
    turnStartContext helper to remove duplicated Output boilerplate.
  • Trim verbose multi-paragraph doc blocks across all files while
    keeping concise but informative godoc on public APIs.

Diff stats

7 files changed, 404 insertions(+), 766 deletions(-)

File Before After
types.go 314 199
executor.go 447 330
handler.go 189 200 (now also contains old builtin.go)
builtin.go 96 removed
config.go 63 53
builtins/builtins.go 132 97

Trim ~30% of non-test code in pkg/hooks while keeping every public API
and behavioral contract intact (all hooks tests, runtime hook-wiring
tests, go vet, and golangci-lint pass).

- Unify the Executor event lookup: remove the eventHooks{flat,
  matchers} split and the selectHooks helper. Every event now compiles
  to a single []matcher slice; flat events become one matcher with an
  empty pattern, so dispatch is one filter loop.
- Inline executeHooks + aggregateResults + dedup into Dispatch.
  executeHook's 5-return-value signature becomes runHook returning a
  hookResult. aggregate uses a clean switch over per-hook outcomes.
- Replace the contextEvents switch with a small map[EventType]bool to
  decide which events route plain stdout into AdditionalContext.
- Merge builtin.go into handler.go: registry, factories, and handlers
  now live in one file. HookTypeBuiltin moves into types.go alongside
  HookTypeCommand.
- Compact Config.IsEmpty, convertHooks/convertMatchers, and the
  builtins Register (single map iteration). Extract a small
  turnStartContext helper to remove duplicated Output boilerplate.
- Trim verbose multi-paragraph doc blocks across all files while
  keeping concise but informative godoc on public APIs.

Assisted-By: docker-agent
@dgageot dgageot requested a review from a team as a code owner April 27, 2026 10:30
@dgageot dgageot merged commit 1d9e0f9 into docker:main Apr 27, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants