Skip to content

refactor(cli[add]) Extract duplicated save-config dispatch helpers#530

Open
tony wants to merge 1 commit into
masterfrom
refactor/add-repo-dedup
Open

refactor(cli[add]) Extract duplicated save-config dispatch helpers#530
tony wants to merge 1 commit into
masterfrom
refactor/add-repo-dedup

Conversation

@tony

@tony tony commented Mar 1, 2026

Copy link
Copy Markdown
Member

Summary

Closes #521

  • Extract _save_config_or_log_error() for the try/except/log.exception pattern (used 4x)
  • Extract _extract_current_url() for deriving display URLs from config entries (duplicated in merge/no-merge paths)
  • Extract _handle_skip_action() for SKIP_PINNED/SKIP_EXISTING branches (~30 lines each, duplicated)
  • Both merge and no-merge paths now use local closures + shared helpers

Test plan

  • uv run ruff check . — all checks passed
  • uv run ruff format . — no changes needed
  • uv run mypy — no issues found
  • uv run py.test -vvv — 1175 passed

@codecov

codecov Bot commented Mar 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.79%. Comparing base (e6a62d9) to head (02fd15e).

Files with missing lines Patch % Lines
src/vcspull/cli/add.py 68.00% 2 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #530      +/-   ##
==========================================
+ Coverage   83.30%   83.79%   +0.48%     
==========================================
  Files          32       32              
  Lines        4492     4467      -25     
  Branches      903      902       -1     
==========================================
+ Hits         3742     3743       +1     
+ Misses        499      471      -28     
- Partials      251      253       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tony

tony commented Mar 1, 2026

Copy link
Copy Markdown
Member Author

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@tony

tony commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

Re-authored on current master. The original branch collided with master's own add.py refactor (the AddAction SKIP_PINNED/SKIP_EXISTING split), which had increased the duplication this PR targets — there are now six identical save-with-error-handling blocks and two identical current-URL derivations. Kept the PR's helper primitives (_save_config_or_log_error, _extract_current_url) and routed all six save sites + both URL derivations through them, preserving the merge vs no-merge dispatcher (save_config vs _save_ordered_items) via a passed closure. Both helpers carry doctests plus parametrized functional tests. Full gate (ruff/mypy/pytest/build-docs) green.

@tony tony force-pushed the refactor/add-repo-dedup branch from 0674d9d to 01640cd Compare July 5, 2026 14:41
why: master's add flow repeats the same save-with-error-handling block at
six sites (three merge-path via save_config, three no-merge-path via
_save_ordered_items) and derives the "current URL" from an existing entry
with two identical isinstance ladders. The AddAction SKIP_PINNED/
SKIP_EXISTING split roughly doubled these over time.

what:
- Add _save_config_or_log_error(save_fn, *, config_file_path) wrapping the
  try/save/except-log-traceback pattern; each call site keeps its own
  success message via the returned bool
- Add _extract_current_url(existing_config) for the string/dict/other
  URL derivation
- Route all six save sites and both URL derivations through the helpers,
  preserving the merge vs no-merge dispatcher (save_config vs
  _save_ordered_items) via a passed closure
- Cover both helpers with doctests and parametrized functional tests
@tony tony force-pushed the refactor/add-repo-dedup branch from 01640cd to 02fd15e Compare July 5, 2026 15:00
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.

refactor(cli[add]) Extract duplicated save-config dispatch helpers

1 participant