Skip to content

refactor: extract duplicated patterns into shared helpers#20

Merged
nathanialhenniges merged 1 commit into
mainfrom
FLUFF-refactor-extract-helpers
Mar 22, 2026
Merged

refactor: extract duplicated patterns into shared helpers#20
nathanialhenniges merged 1 commit into
mainfrom
FLUFF-refactor-extract-helpers

Conversation

@nathanialhenniges
Copy link
Copy Markdown
Member

Summary

  • Created 4 shared helper utilities (safeErrorReply, requireOwner, sendToMainChannel, updateGuildPremiumStatus) to replace copy-pasted patterns
  • Updated 28 source files to use the new helpers, removing ~200 lines of duplicated code
  • All 228 tests pass, typecheck clean, lint clean

Test plan

  • bun run typecheck passes
  • bun test — 228 tests, 0 failures
  • bun run lint passes

🤖 Generated with Claude Code

Create 4 shared helpers (safeErrorReply, requireOwner, sendToMainChannel,
updateGuildPremiumStatus) to replace copy-pasted patterns across 28 files,
removing ~200 lines of duplicated code while preserving identical behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 22, 2026

Warning

Rate limit exceeded

@nathanialhenniges has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 0 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9de40e24-1a80-47fc-8ace-5f662cc1dc6d

📥 Commits

Reviewing files that changed from the base of the PR and between b41a344 and 251584c.

📒 Files selected for processing (32)
  • src/commands/about.ts
  • src/commands/admin/activity/create.ts
  • src/commands/admin/activity/list.ts
  • src/commands/admin/activity/remove.ts
  • src/commands/admin/index.ts
  • src/commands/admin/quote/create.ts
  • src/commands/admin/quote/list.ts
  • src/commands/admin/quote/remove.ts
  • src/commands/admin/suggestion/approve.ts
  • src/commands/admin/suggestion/list.ts
  • src/commands/admin/suggestion/reject.ts
  • src/commands/admin/suggestion/stats.ts
  • src/commands/changelog.ts
  • src/commands/help.ts
  • src/commands/invite.ts
  • src/commands/owner/index.ts
  • src/commands/owner/premium/testCreate.ts
  • src/commands/owner/premium/testDelete.ts
  • src/commands/owner/premium/testList.ts
  • src/commands/premium.ts
  • src/commands/quote.ts
  • src/commands/setup/channel.ts
  • src/commands/setup/index.ts
  • src/commands/setup/schedule.ts
  • src/commands/suggestion.ts
  • src/events/entitlementCreate.ts
  • src/events/entitlementDelete.ts
  • src/events/entitlementUpdate.ts
  • src/utils/commandErrors.ts
  • src/utils/entitlementHelpers.ts
  • src/utils/mainChannel.ts
  • src/utils/ownerGuard.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch FLUFF-refactor-extract-helpers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nathanialhenniges nathanialhenniges merged commit 7801952 into main Mar 22, 2026
5 checks passed
@nathanialhenniges nathanialhenniges deleted the FLUFF-refactor-extract-helpers branch March 22, 2026 17:01
nathanialhenniges added a commit that referenced this pull request May 16, 2026
…ragglers to withCommandLogging (#22)

* refactor: extract buildBrandedEmbed + logEntitlementEvent, migrate stragglers to withCommandLogging

Follow-up duplication audit after #20. Consolidates remaining copy-paste:

- New src/utils/embedHelpers.ts with buildBrandedEmbed, BRAND_COLOR, BRAND_FOOTER.
  Single source of truth for brand color (0xfadb7f) and footer; previously
  duplicated across 9 callsites.
- New logEntitlementEvent in src/utils/entitlementHelpers.ts. Entitlement
  Create/Delete/Update events now share one logging shape.
- Migrated 7 commands from hand-rolled try/catch + executing/error logging
  to withCommandLogging: help, about, invite, changelog, admin/quote/create,
  admin/quote/remove, admin/activity/create, admin/activity/remove,
  admin/suggestion/stats, setup/channel. Fixes setup/channel logging the wrong
  command name on success/error.
- Refactored premium-cmd, setup/schedule, quoteHelpers.buildMotivationEmbed,
  premium.buildPremiumUpsell, admin/suggestion/stats, changelog, about,
  admin/quote/create embed scaffolding through buildBrandedEmbed.

Tests: 244 pass, 0 fail. typecheck + lint clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* fix(tests): isolate quoteHelpers from cross-file mock leakage

CI surfaced 3 quoteHelpers test failures: the bun:test mock.module
registry is process-global, so tests/commands/quote.test.ts and
tests/worker/sendMotivation.test.ts mocking src/utils/quoteHelpers.js
poisoned tests/utils/quoteHelpers.test.ts whenever bun's test discovery
walked those files first. Same root cause #21 fought with readyDeps /
commandRegistry shims.

Apply the same shim pattern:

- New src/commands/quoteDeps.ts re-exports buildMotivationEmbed,
  getRandomMotivationQuote, resolveQuoteAuthor. src/commands/quote.ts
  imports from the shim. quote.test.ts mocks the shim, not the real
  module.
- New src/worker/jobs/sendMotivationDeps.ts mirrors the same shim for
  the worker job. sendMotivation.test.ts mocks the shim.

Local: 244 pass, 0 fail. typecheck clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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