Skip to content

New commands: add and add-from-fs #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft

New commands: add and add-from-fs #465

wants to merge 26 commits into from

Conversation

tony
Copy link
Member

@tony tony commented May 10, 2025

Fixes:

Summary by Sourcery

Add new CLI commands add and add-from-fs to vcspull for managing repository configuration

New Features:

  • Implement add command to add a single repository to vcspull configuration
  • Implement add-from-fs command to scan and add multiple git repositories from a directory

Enhancements:

  • Extend CLI parser to support new subcommands
  • Improve configuration file handling with more flexible path and key management

Copy link

sourcery-ai bot commented May 10, 2025

Reviewer's Guide

This pull request introduces two new CLI subcommands, add and add-from-fs, to vcspull, enhancing its repository management capabilities. The add command is implemented in src/vcspull/cli/add.py and allows users to manually specify repository details (URL, name, target path) for addition to the YAML configuration. The add-from-fs command, housed in src/vcspull/cli/add_from_fs.py, scans a specified filesystem directory for Git repositories, automatically extracts their remote 'origin' URLs, and adds them to the configuration, optionally after user confirmation. Both functionalities are integrated into the main CLI by updating src/vcspull/cli/__init__.py to include new argument subparsers and modify the command dispatch logic. This involved refactoring create_parser to manage and return a collection of all subparsers and updating the cli function to robustly pass arguments to the respective command handlers.

File-Level Changes

Change Details Files
Implemented add command for manual repository addition to the configuration.
  • Created add.py module with logic to parse repository details (URL, name, path) and update the YAML configuration.
  • Defined command-line arguments for the add subparser within add.py.
  • Integrated the add subparser and its handler into the main CLI structure in __init__.py.
src/vcspull/cli/add.py
src/vcspull/cli/__init__.py
Implemented add-from-fs command to discover local Git repositories and add them to the configuration.
  • Created add_from_fs.py module with logic to scan directories, extract Git remote URLs, and update the configuration, including an interactive confirmation step.
  • Defined command-line arguments for the add-from-fs subparser within add_from_fs.py.
  • Integrated the add-from-fs subparser and its handler into the main CLI structure in __init__.py.
src/vcspull/cli/add_from_fs.py
src/vcspull/cli/__init__.py
Refactored CLI argument parsing and command dispatching in __init__.py.
  • Modified create_parser function to support the registration and retrieval of multiple subparsers.
  • Updated the main cli function to correctly dispatch to the new command handlers based on the invoked subparser.
  • Improved argument handling when calling command handlers by checking for attribute existence on the parsed arguments object.
src/vcspull/cli/__init__.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@tony tony changed the title !squash initial: add and add-from-fs New commands: add and add-from-fs May 10, 2025
@tony tony force-pushed the scanner-and-add branch 2 times, most recently from a36fbef to 69a222e Compare May 10, 2025 16:36
Copy link

codecov bot commented May 10, 2025

Codecov Report

Attention: Patch coverage is 58.10811% with 93 lines in your changes missing coverage. Please review.

Project coverage is 72.52%. Comparing base (5da98d4) to head (9af2ef7).

Files with missing lines Patch % Lines
src/vcspull/cli/add.py 20.00% 52 Missing ⚠️
src/vcspull/cli/add_from_fs.py 67.96% 30 Missing and 11 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #465      +/-   ##
==========================================
- Coverage   78.93%   72.52%   -6.42%     
==========================================
  Files           8       10       +2     
  Lines         413      626     +213     
  Branches       85      133      +48     
==========================================
+ Hits          326      454     +128     
- Misses         52      126      +74     
- Partials       35       46      +11     

☔ View full report in Codecov by Sentry.
📢 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 force-pushed the scanner-and-add branch 3 times, most recently from d37cb7e to 628830e Compare May 17, 2025 11:49
@tony tony force-pushed the scanner-and-add branch 3 times, most recently from e85482d to e26036d Compare June 1, 2025 11:07
@tony tony force-pushed the scanner-and-add branch from e26036d to d1e116f Compare June 19, 2025 11:29
@tony tony force-pushed the scanner-and-add branch from d1e116f to 662f00a Compare June 19, 2025 11:32
@tony tony force-pushed the scanner-and-add branch from 662f00a to f5accf6 Compare June 19, 2025 11:53
tony and others added 6 commits June 19, 2025 06:53
- Fix sync() function call to pass pathlib.Path for config parameter
- Add save_config_yaml to helpers and fix imports
- Improve test teardown to use shutil.rmtree
- Add missing pathlib import in CLI __init__.py
- Set logging level in tests for proper log capture
The sync() function requires config as a parameter even when None.
Update the kwargs filtering to always include config in the allowed
parameters list.
- Fix line length issues (E501) in CLI modules
- Replace open() with Path.open() (PTH123)
- Remove redundant exception objects in logging.exception() calls (TRY401)
- Break long strings across multiple lines for better readability
- All ruff and mypy checks now pass for the new CLI commands
- Add save_config_yaml to vcspull.config module using ConfigReader._dump
- Remove duplicate implementations from cli/add.py and cli/add_from_fs.py
- Update imports to use the centralized function
- Remove duplicate from test helpers
- Follows DRY principle and provides consistent YAML formatting
- Replace complex repo_name_or_url parsing with explicit name and url args
- Remove 150+ lines of confusing comments and logic
- Add clear --path and --dir options for specifying location
- Make command usage intuitive: vcspull add <name> <url>
- Reduce add_repo function from 270 to 163 lines
- Improve help text and parameter documentation
… patterns

why: Ensure consistency with project patterns and improve code maintainability.
what:
- Updated module and function docstrings to match NumPy style
- Cleaned up imports and removed unnecessary comments
- Fixed error handling to match sync.py patterns
- Fixed type annotations for mypy compliance
- Fixed non-recursive scanning bug in add_from_fs.py
- Removed unused helper functions in tests

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
tony and others added 10 commits June 19, 2025 16:28
…notation

why: Fix mypy error for variable redefinition on line 201.
what:
- Remove redundant type annotation for determined_base_key in non-recursive branch
- Variable was already declared with type annotation in recursive branch

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…ositories

why: Users need visibility into which repositories already exist in configuration and where they are located.
what:
- Show count and detailed list of existing repositories when found
- Display repository name, URL, config path, and file location for each existing repo
- Simplify logic by consolidating duplicate repository checking code
- Improve user experience with more informative output

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
… existing repo reporting

why: Ensure the enhanced output functionality works correctly across different scenarios.
what:
- Update existing test to verify new detailed output format
- Add test for multiple existing repositories with detailed listing
- Add test for mixed scenario with both existing and new repositories
- Verify count, individual repo details, and final status messages
- Test output includes repo name, URL, config path, and file location

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…ommands

why: CLI add/add-from-fs commands should have clean output like print() while preserving debug output for VCS operations.
what:
- Add SimpleLogFormatter that outputs only the message without extra formatting
- Configure specific loggers for vcspull.cli.add and vcspull.cli.add_from_fs to use simple formatter
- Keep DebugLogFormatter for vcspull core operations and sync commands
- Prevent logger propagation to avoid duplicate output
- Maintain detailed VCS operation logging for sync functionality

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…ilities

why: Ensure proper testing coverage for all logging formatters and setup functionality
what:
- Add test_log.py with comprehensive test coverage for all log components
- Test LogFormatter, DebugLogFormatter, SimpleLogFormatter, RepoLogFormatter classes
- Test RepoFilter functionality and setup_logger behavior
- Test integration scenarios with actual loggers
- Follow vcspull testing patterns with NamedTuple parametrized tests
- Include proper pytest fixtures for logger cleanup

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…rting

why: Follow best practices for exception logging and provide better debugging info
what:
- Replace log.error with log.exception in exception handlers
- Maintain existing debug traceback functionality
- Apply to both add.py and add_from_fs.py modules

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
why: Ensure code passes linting and follows project formatting standards
what:
- Fix line length violations by splitting long strings
- Improve code readability with proper line breaks
- Use dict() constructor for cleaner code
- Remove unused loop variables with underscore prefix

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
… clean output

why: Ensure CLI sync command provides clean user-facing output like print()
what:
- Extend SimpleLogFormatter to vcspull.cli.sync logger
- Consolidate CLI logger setup with DRY loop pattern
- Maintain clean output for all user-facing CLI commands

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…e stderr

why: SimpleLogFormatter outputs to stderr via StreamHandler, but test only captured stdout
what:
- Update output capture to include both stdout and stderr
- Use iterable unpacking for cleaner code style
- Ensure all CLI log messages are properly captured in tests

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
…ync logger

why: Ensure CLI sync logger is properly configured with SimpleLogFormatter
what:
- Add test_setup_logger_creates_cli_sync_logger test case
- Update logger cleanup fixture to include sync logger
- Update all setup_logger tests to clear sync logger handlers
- Verify sync logger uses SimpleLogFormatter for clean output

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
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