refactor(router): extract shared credential resolution & platform API helpers#492
Conversation
|
🔍 Reviewing PR... |
nhopeatall
left a comment
There was a problem hiding this comment.
LGTM — Clean deduplication of credential resolution and GitHub header boilerplate. The three credential/header helpers (resolveTrelloCredentials, resolveJiraCredentials, resolveGitHubHeaders) are well-scoped, the behavioral equivalence with the original code is correct, and the test coverage is solid.
Minor Observations (non-blocking)
-
Unused high-level helpers:
postTrelloComment,postGitHubComment, andpostJiraCommentare exported and tested but have zero consumers outside the test file. If these are pre-positioned for future use that's fine, but worth noting they're dead code today. -
Stale comment in
notifications.ts:168: The comment says "Use v2 API which accepts plain text, avoiding the pm/jira/adf dependency" — thepm/jira/adfavoidance rationale is now slightly misleading sincenotifications.tstransitively importsmarkdownToAdfthroughplatformClients.ts. The code still correctly uses v2/plain-text for notifications, but the comment could be simplified to just explain the v2 choice without referencing dependency avoidance.
|
@aaight address code review concerns |
Request AddressedWhat was askedAddress code review concerns from @nhopeatall's review. Changes Made
Verification
|
- Remove dead-code `postTrelloComment`, `postGitHubComment`, `postJiraComment` exports from platformClients.ts (zero consumers outside tests) - Remove unused `markdownToAdf` import from platformClients.ts - Remove 15 corresponding tests for the removed helpers - Fix stale comment in notifications.ts that incorrectly referenced pm/jira/adf dependency avoidance (now transitively imported) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Addressed both review concerns from @nhopeatall:
All router tests pass (200 tests). The 6 failures in |
|
🔍 Reviewing PR... |
nhopeatall
left a comment
There was a problem hiding this comment.
LGTM — Clean extraction of duplicated credential resolution and GitHub header construction into a well-structured shared module. The refactoring is mechanical and correct:
resolveTrelloCredentials,resolveJiraCredentials, andresolveGitHubHeadersproperly consolidate ~150 lines of repeated boilerplate across four router modules.- Error semantics preserved: try/catch →
nullreturn matches the original catch-and-return-null pattern in every call site. - The
JiraCredentialsinterface smartly pre-computes the Base64 auth string, eliminating repeatedBuffer.from()calls. - All four refactored modules (
acknowledgments.ts,reactions.ts,notifications.ts,pre-actions.ts) correctly swap to the shared helpers with no behavioral regressions. - Tests cover happy path, missing credentials, missing project, and missing JIRA base URL — the key failure modes.
One minor note: notifications.ts previously resolved JIRA base URL via project?.jira?.baseUrl directly, while the shared helper routes through getJiraConfig() (which checks pm.type). This is technically a behavioral change, but it's the correct direction — it aligns notifications.ts with how acknowledgments.ts and reactions.ts already resolved the URL.
The PR description mentions six helpers and 24 tests, but the actual implementation has three helpers and 9 tests — likely an outdated description from an earlier iteration. The code itself is what matters, and it's solid.
CI green (lint, typecheck, 215 tests passing).
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>
Summary
Extracts duplicated credential resolution and GitHub header boilerplate from four router modules into a new shared
src/router/platformClients.tsmodule.src/router/platformClients.ts— six shared helpers:resolveTrelloCredentials,resolveJiraCredentials,resolveGitHubHeaders,postTrelloComment,postGitHubComment,postJiraCommentacknowledgments.ts,reactions.ts,notifications.ts,pre-actions.ts— ~150 lines of duplicated boilerplate eliminated, zero functional changestests/unit/router/platformClients.test.ts— 24 tests covering happy path, credential failure → null, API failure → null for all six helpersKey design constraints preserved:
fetch()(nosrc/trello/client.tsorsrc/github/client.ts) — router Docker image isolation maintainedpostJiraCommentsupports both v3+ADF (default) and v2+plaintext mode viauseAdfparameterCard: https://trello.com/c/s1IJSCXo/78-refactor-src-router-extract-duplicated-credential-resolution-platform-api-helpers
Test plan
🤖 Generated with Claude Code