Skip to content

refactor(router): extract shared credential resolution & platform API helpers#492

Merged
zbigniewsobiecki merged 2 commits intodevfrom
refactor/router-platform-clients
Feb 22, 2026
Merged

refactor(router): extract shared credential resolution & platform API helpers#492
zbigniewsobiecki merged 2 commits intodevfrom
refactor/router-platform-clients

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Feb 22, 2026

Summary

Extracts duplicated credential resolution and GitHub header boilerplate from four router modules into a new shared src/router/platformClients.ts module.

  • New module src/router/platformClients.ts — six shared helpers: resolveTrelloCredentials, resolveJiraCredentials, resolveGitHubHeaders, postTrelloComment, postGitHubComment, postJiraComment
  • Refactored acknowledgments.ts, reactions.ts, notifications.ts, pre-actions.ts — ~150 lines of duplicated boilerplate eliminated, zero functional changes
  • New tests tests/unit/router/platformClients.test.ts — 24 tests covering happy path, credential failure → null, API failure → null for all six helpers

Key design constraints preserved:

  • All helpers use raw fetch() (no src/trello/client.ts or src/github/client.ts) — router Docker image isolation maintained
  • Fire-and-forget: errors caught and logged, never propagated
  • JIRA postJiraComment supports both v3+ADF (default) and v2+plaintext mode via useAdf parameter

Card: https://trello.com/c/s1IJSCXo/78-refactor-src-router-extract-duplicated-credential-resolution-platform-api-helpers

Test plan

  • 215 router tests passing (191 existing + 24 new)
  • TypeScript typecheck passes
  • Biome lint passes on all modified files

🤖 Generated with Claude Code

@nhopeatall
Copy link
Copy Markdown
Collaborator

🔍 Reviewing PR...

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and postJiraComment are 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" — the pm/jira/adf avoidance rationale is now slightly misleading since notifications.ts transitively imports markdownToAdf through platformClients.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.

@zbigniewsobiecki
Copy link
Copy Markdown
Member

@aaight address code review concerns

@aaight
Copy link
Copy Markdown
Collaborator Author

aaight commented Feb 22, 2026

Request Addressed

What was asked

Address code review concerns from @nhopeatall's review.

Changes Made

  • Removed dead code: Deleted unused postTrelloComment, postGitHubComment, postJiraComment exports and the markdownToAdf import from platformClients.ts (-100 lines)
  • Removed dead tests: Deleted 15 tests for the removed helpers from platformClients.test.ts (-190 lines)
  • Fixed stale comment: Updated misleading pm/jira/adf dependency comment in notifications.ts to accurately describe the v2 plain-text choice
  • Updated module docstring: Simplified platformClients.ts header to reflect its focused scope (credential resolution + headers only)

Verification

  • All 200 router tests passing
  • TypeScript typecheck passes
  • Biome lint passes

- 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>
@aaight
Copy link
Copy Markdown
Collaborator Author

aaight commented Feb 22, 2026

Addressed both review concerns from @nhopeatall:

  1. Removed unused high-level helperspostTrelloComment, postGitHubComment, and postJiraComment were dead code (zero consumers outside tests). Removed all three from platformClients.ts along with the unused markdownToAdf import, and removed the corresponding 15 tests. The module now contains only the credential resolution + header helpers that are actually consumed.

  2. Fixed stale comment in notifications.ts — Updated the comment at line 168 from referencing pm/jira/adf dependency avoidance (misleading since it's now transitively imported via platformClients.ts) to simply explaining the v2 plain-text choice for timeout messages.

All router tests pass (200 tests). The 6 failures in config/projects.test.ts are pre-existing and unrelated.

@nhopeatall
Copy link
Copy Markdown
Collaborator

🔍 Reviewing PR...

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and resolveGitHubHeaders properly consolidate ~150 lines of repeated boilerplate across four router modules.
  • Error semantics preserved: try/catch → null return matches the original catch-and-return-null pattern in every call site.
  • The JiraCredentials interface smartly pre-computes the Base64 auth string, eliminating repeated Buffer.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).

@zbigniewsobiecki zbigniewsobiecki merged commit d2d53cf into dev Feb 22, 2026
5 checks passed
aaight pushed a commit that referenced this pull request Feb 23, 2026
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>
@zbigniewsobiecki zbigniewsobiecki deleted the refactor/router-platform-clients branch March 16, 2026 16:43
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.

3 participants