Skip to content

Refactor: Separate presentation logic from business logic with early-return patterns#8

Merged
irskep merged 1 commit intomainfrom
refactor
Jul 13, 2025
Merged

Refactor: Separate presentation logic from business logic with early-return patterns#8
irskep merged 1 commit intomainfrom
refactor

Conversation

@irskep
Copy link
Owner

@irskep irskep commented Jul 13, 2025

Summary

This refactoring separates presentation logic (click handlers) from business logic and improves code maintainability by applying early-return patterns throughout the codebase.

  • Separate concerns: Extract business logic from CLI commands into dedicated services.py module
  • Early-return patterns: Replace deeply nested conditionals with cleaner control flow
  • Improve testability: Create composable functions with single responsibilities
  • Add comprehensive tests: Achieve 67% test coverage with 43 passing tests

Changes

New Architecture

  • services.py: Core business logic for CI status, job details, log processing, and workflow watching
  • Data classes: CIStatusResult, JobDetails, WorkflowStepInfo for type safety
  • CLI refactoring: Commands now focus purely on presentation using business logic functions

Key Improvements

  • watch command: Reduced from 120+ lines to ~20 lines by extracting logic
  • Early returns: Eliminated 3-4 level deep nesting throughout codebase
  • Reusable functions: Composable logic that can be easily tested and maintained
  • Better error handling: Centralized error processing patterns

Test Coverage

  • New test files: test_services.py, test_cli_refactored.py
  • 29 new tests covering business logic and presentation layer
  • All functionality preserved with improved maintainability

Test plan

  • All existing tests pass (14 tests)
  • New business logic tests pass (29 tests)
  • CLI still works correctly (python -m cimonitor --help)
  • Pre-commit hooks pass (ruff, formatting, etc.)
  • Code coverage improved to 67%

🤖 Generated with Claude Code

@irskep irskep merged commit 84ad6ac into main Jul 13, 2025
6 checks passed
@irskep irskep deleted the refactor branch July 13, 2025 21:10
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