refactor: deduplicate update prompt logic#24
Conversation
Extract shared update prompt and git pull logic into _zush_do_update() helper function. Both _zush_prompt_available_update() and update-zush() now use this helper, eliminating 26 lines of duplicate code. Fixes #17 Co-authored-by: Scott Hyndman <shyndman@users.noreply.github.com>
Code Review: PR #24 - Refactor: Deduplicate Update Prompt LogicThanks for this refactoring! The deduplication of the update prompt logic is a solid improvement that reduces code maintenance burden. Here's my detailed review: ✅ Strengths
🐛 Potential Issues
🔒 Security Considerations
⚡ Performance ConsiderationsNo performance concerns. The refactoring doesn't introduce any new operations or overhead - it's a pure extraction of existing logic. 🧪 Test CoverageIssue: I couldn't find any test files in the repository. Recommendation: Consider adding tests for this critical update mechanism, especially:
You might want to look into zsh testing frameworks like zunit or create simple integration tests. 📝 Minor Suggestions
🎯 Overall AssessmentThis is a well-executed refactoring that successfully achieves its goal. The code quality is good, follows existing conventions, and has no critical bugs. The minor suggestions above are purely for future maintainability and robustness. Recommendation: ✅ Approve with minor suggestions The PR is ready to merge as-is, though addressing the return value consistency would make the code more robust for future changes. 🤖 Review generated with Claude Code |
There was a problem hiding this comment.
Pull request overview
This PR refactors the update prompt logic by extracting 26 lines of duplicate code into a new helper function _zush_do_update(). Both _zush_prompt_available_update() and update-zush() previously contained identical update prompt and git pull logic, which has now been consolidated into a single reusable helper.
Key changes:
- Introduced
_zush_do_update()helper function to handle update prompts and git pull operations - Simplified
_zush_prompt_available_update()to call the helper instead of duplicating the update logic - Simplified
update-zush()to call the helper instead of duplicating the update logic - Cleaned up trailing whitespace on lines 118 and 124
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| echo " Restart your shell to use the latest version." | ||
| rm -f "$ZUSH_UPDATE_AVAILABLE_FILE" | ||
| else | ||
| echo " ⚠️ Update failed. Try manually: cd ~/.config/zush && git pull" |
There was a problem hiding this comment.
The function doesn't return a non-zero status when git pull fails. Consider adding return 1 in the else block after the error message to properly signal failure. This would allow callers to handle the failure case if needed in the future.
| echo " ⚠️ Update failed. Try manually: cd ~/.config/zush && git pull" | |
| echo " ⚠️ Update failed. Try manually: cd ~/.config/zush && git pull" | |
| return 1 |
PR Review: Refactor to Deduplicate Update Prompt Logic✅ Overall AssessmentThis is a solid refactoring that successfully eliminates code duplication while maintaining functionality. The PR achieves its stated goal of reducing 54 lines of duplicate code by extracting shared logic into a reusable helper function. 🎯 Code Quality & Best PracticesStrengths:
Minor Suggestions:
🐛 Potential Bugs or IssuesNo critical bugs identified, but there's one edge case to consider: Race condition consideration (lib/update-check.zsh:90):
⚡ Performance ConsiderationsNo performance concerns. The refactoring:
🔒 Security ConcernsNo security issues identified. The code:
🧪 Test CoverageObservation: No automated tests exist in the repository for this functionality. Recommendations for future work (not blocking for this PR):
Given the project structure and shell scripting nature, manual testing is appropriate here. 📝 Documentation
✨ SummaryThis is ready to merge with only minor suggestions for enhancement. The refactoring successfully:
The suggestions above are optional improvements that could be addressed in a follow-up if desired, but they don't block this PR. Verdict: LGTM! 🚀 Great work on keeping the codebase clean and maintainable! 🦥 |
Code Review: PR #24 - Refactor: Deduplicate Update Prompt LogicSummaryThis PR successfully addresses issue #17 by extracting duplicate update prompt logic into a shared helper function. The refactoring is clean and achieves its stated goal of reducing code duplication. ✅ Strengths
🔍 Code Quality ObservationsGood Practices
Consistency with Codebase
|
Fixes #17
Extracts shared update prompt and git pull logic into
_zush_do_update()helper function. Both_zush_prompt_available_update()andupdate-zush()now use this helper, eliminating 26 lines of duplicate code.Changes
_zush_do_update()helper function_zush_prompt_available_update()to call helperupdate-zush()to call helperGenerated with Claude Code