Skip to content

refactor: extract shared transaction helper from duplicated runReservationTransaction/runEpicTransaction #121

Open

Description

@yvonnedevlinrh

Summary

PR #120 introduced two structurally identical transaction helpers as part of the lint-debt resolution:

  • internal/comms/reservation.go → runReservationTransaction(work, commit, rollback func() error) error
  • internal/org/epic.go → runEpicTransaction(work, commit, rollback func() error) error

Both are byte-for-byte identical in logic: committed flag, deferred rollback guarded with sql.ErrTxDone, and errors.Join for error aggregation. The duplication was intentional — the spec (design.md) scoped work as per-package correctness without cross-cutting refactors.

Proposed Change

Extract a shared helper into internal/db, e.g.:

// RunTransaction executes work within a transaction lifecycle.
// It calls commit on success and ensures rollback is called exactly
// once on failure, guarding against sql.ErrTxDone.
func RunTransaction(work, commit, rollback func() error) error

Then replace both package-local copies with calls to db.RunTransaction.

Acceptance Criteria

  • Shared helper exists in internal/db
  • internal/comms/reservation.go uses the shared helper
  • internal/org/epic.go uses the shared helper
  • Existing tests for both packages continue to pass
  • Shared helper has its own unit tests in internal/db
  • No third copy of this pattern exists in the codebase

Context

  • Introduced in: fix: resolve project-wide lint debt #120
  • Convention: go.md CS-010 [SHOULD] — avoid duplicated logic across packages
  • Priority: Low — both copies are correct and tested; this is a maintainability improvement to prevent a third copy from appearing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions