refactor: extract duplicate command hash logic into _compute_command_hash (#31) #65
No reviewers
Labels
No Label
ai-changes-requested
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
in-next-release
status/in-progress
status/pr-open
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-v2#65
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/major-domo-v2-31"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes #31 — DRY violation in
bot.pywhere_should_sync_commandsand_save_command_hashboth contained an identical ~35-line block that built a command data list and computed a SHA-256 hash.Changes
_compute_command_hash(self) -> str— a new synchronous helper that builds the command data list and returns the hex digest_should_sync_commandsnow callsself._compute_command_hash()instead of inlining the logic_save_command_hashnow callsself._compute_command_hash()instead of inlining the logicFiles Changed
bot.py— 37 insertions, 67 deletions (net −30 lines)Tests
924 tests pass. 6 pre-existing failures in
test_commands_profile_images.pyare unrelated to this change (those files were already modified onmainbefore this branch).AI Code Review
Files Reviewed
bot.py(modified)Findings
Correctness
_compute_command_hash(self) -> stris a faithful, byte-for-byte equivalent of the inlined logic it replaces in both_should_sync_commandsand_save_command_hash. No behavioral change.asyncis needed.-> stris accurate (hexdigest is always astr).try/exceptblocks, so any exception raised by_compute_command_hash(e.g., fromself.tree.get_commands()) is still caught and handled properly.Security
Style & Conventions
_compute_command_hash) is consistent with the existing_should_sync_commands/_save_command_hashconvention._should_sync_commandsis logical and readable.Suggestions
_compute_command_hashdirectly could be added in the future, but the method's behavior is already exercised indirectly through the callers.Verdict: APPROVED
Clean DRY refactoring. The extracted helper is correctly typed, synchronous, and the calling methods are unchanged in behavior. No issues found. (Note: posted as COMMENT — Gitea does not permit self-approval.)
Automated review by Claude PR Reviewer