Skip to content

refactor: eliminate shared mutable state via struct-based DI#235

Merged
indaco merged 9 commits intomainfrom
refactor/eliminate-shared-mutable-state
Mar 19, 2026
Merged

refactor: eliminate shared mutable state via struct-based DI#235
indaco merged 9 commits intomainfrom
refactor/eliminate-shared-mutable-state

Conversation

@indaco
Copy link
Copy Markdown
Owner

@indaco indaco commented Mar 19, 2026

Description

Replace package-level function variables with struct-based dependency injection across packages. This eliminates shared mutable state and made dependency flow implicit.

Changes by package:

  • changeloggenerator: new GitOps struct encapsulates git function fields; IsInteractiveFn/ConfirmMergeFn moved to plugin struct fields
  • dependencycheck: format-specific read/write function vars moved to DependencyCheckerPlugin struct fields, initialized in constructor
  • commitparser/gitlog: new GitLog struct with ExecCommandFn field; GetCommitsFn type and DefaultGetCommitsFn() factory for callers
  • tagmanager: nowFunc global replaced with optional NowFunc parameter on NewTemplateData()
  • commands/bump: new bumpDeps struct with context-based injection via context.WithValue; holds inference, bumper, and commit retrieval functions
  • extensions: LoadExtensionManifestFn global var replaced with exported LoadExtensionManifest() function; all callers updated
  • extensionmgr: removed copyDirFn and defaultFileCopier global vars; tests use NewOSFileCopier() or MockFileCopier directly
  • cli/config tests: replaced manual os.Getwd/os.Chdir/os.Unsetenv with t.Chdir() and t.Setenv() for proper test isolation

Related Issue

  • None

Notes for Reviewers

  • Only readFileFn/writeFileFn in dependencycheck/parsers.go remain as package-level vars (adapter-level, not plugin-level)

@indaco indaco merged commit 1b62a43 into main Mar 19, 2026
7 checks passed
@indaco indaco deleted the refactor/eliminate-shared-mutable-state branch March 19, 2026 11:28
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.

1 participant