Skip to content

refactor(router): extract platformClients.ts to eliminate credential resolution duplication#494

Closed
aaight wants to merge 2 commits intodevfrom
refactor/platform-clients
Closed

refactor(router): extract platformClients.ts to eliminate credential resolution duplication#494
aaight wants to merge 2 commits intodevfrom
refactor/platform-clients

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Feb 23, 2026

Summary

Refactors the src/router/ platform-dispatch files to eliminate ~20× duplicated credential resolution scaffolding across acknowledgments.ts, reactions.ts, and notifications.ts.

  • Extracted src/router/platformClients.ts: Centralized credential resolution helpers for Trello (getTrelloCredentialsForProject), JIRA (getJiraAuthForProject), and GitHub (getGitHubTokenForProject). Also moved bot identity caches (resolveTrelloBotMemberId, resolveJiraBotAccountId) and the JIRA cloudId cache (getJiraCloudId) to this shared module.
  • Simplified acknowledgments.ts: Replaced 6× duplicated let x; try { x = await getIntegrationCredential(...) blocks with 2-line platform client calls (~333→197 lines).
  • Simplified reactions.ts: Replaced credential scaffolding in 3 platform senders with platform client calls (~283→229 lines).
  • Simplified notifications.ts: Replaced credential scaffolding in Trello and JIRA timeout notifiers with platform client calls (~221→205 lines).
  • Created tests/unit/router/platformClients.test.ts: 30 new tests covering credential resolution, caching, TTL expiry, and error handling for all platform client helpers.
  • Backward compatibility: Bot identity helpers and cache reset functions are re-exported from acknowledgments.ts so existing callers are unaffected.

Test plan

  • All 221 router tests pass (including 30 new platformClients.test.ts tests)
  • TypeScript typecheck passes with zero errors
  • Biome lint passes with zero errors
  • Pre-existing test failures in config/projects.test.ts confirmed to be pre-existing (not introduced by this PR)

Card

https://trello.com/c/7lj1Vu6W/80-find-top-candidate-for-refactoring-and-plan-clean-refactoring-of-it-look-for-god-classes-modules-functions-files-and-code-duplic

🤖 Generated with Claude Code

@zbigniewsobiecki
Copy link
Copy Markdown
Member

@aaight resolve conflicts and explain how did they happen

@aaight
Copy link
Copy Markdown
Collaborator Author

aaight commented Feb 23, 2026

Request Addressed

What was asked

Resolve merge conflicts with the dev branch and explain how they happened.

Changes Made

  • Merged dev into refactor/platform-clients, resolving conflicts in all 5 files
  • Adopted dev's naming convention from PR refactor(router): extract shared credential resolution & platform API helpers #492 (resolveTrelloCredentials, resolveJiraCredentials, resolveGitHubHeaders, JiraCredentials.auth)
  • Preserved this PR's unique additions (bot identity caches, JIRA cloudId cache, GitHub token resolution) in platformClients.ts
  • Updated all callers and tests to use consistent naming
  • Combined both PRs' test suites (now 33 tests in platformClients.test.ts)

Root Cause

PR #492 (refactor/router-platform-clients) was merged to dev while this PR was open. Both PRs independently extracted credential resolution into platformClients.ts but with different naming conventions and scope.

Verification

  • All 229 router tests passing
  • TypeScript typecheck passing (zero errors)
  • Biome lint passing (zero errors)
  • Pre-existing config/projects.test.ts failures confirmed unrelated

Merge dev into refactor/platform-clients, resolving conflicts in all 5
files (platformClients.ts, acknowledgments.ts, reactions.ts,
notifications.ts, and the test file).

Conflicts arose because PR #492 (refactor/router-platform-clients) was
merged to dev while this PR was open. Both PRs extracted credential
resolution into platformClients.ts but with different naming conventions
and scope.

Resolution adopts dev's naming (resolveTrelloCredentials,
resolveJiraCredentials, resolveGitHubHeaders, JiraCredentials.auth) and
layers on this PR's additional features (bot identity caches, JIRA
cloudId cache, GitHub token resolution, resolveGitHubTokenForAck).

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

aaight commented Feb 23, 2026

Conflicts resolved and pushed! ✅

What caused the conflicts:

PR #492 () was merged to dev while this PR was open. Both PRs independently extracted credential resolution into platformClients.ts, but with different naming conventions and different scope:

Aspect PR #492 (merged to dev) This PR #494
Trello helper resolveTrelloCredentials getTrelloCredentialsForProject
JIRA helper resolveJiraCredentials getJiraAuthForProject
JIRA auth field auth basicAuth
JIRA type JiraCredentials JiraAuth
GitHub headers resolveGitHubHeaders() helper inline headers
Bot caches stayed in acknowledgments.ts moved to platformClients.ts
JIRA cloudId cache stayed in reactions.ts moved to platformClients.ts
GitHub token resolver stayed in acknowledgments.ts moved to platformClients.ts

Resolution strategy: Adopted dev's naming/interface for the overlapping credential resolution helpers (since PR #492 was already merged and has consumers), then layered on this PR's unique contributions (bot identity caches, JIRA cloudId cache, GitHub token resolution in platformClients.ts).

All 5 conflicted files resolved: platformClients.ts, acknowledgments.ts, reactions.ts, notifications.ts, and platformClients.test.ts. All 229 router tests pass. Typecheck and lint clean.

@zbigniewsobiecki zbigniewsobiecki deleted the refactor/platform-clients branch February 23, 2026 08:02
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.

2 participants