feat: add fetchUser GraphQL query to Linear client#537
Conversation
Add a user(id:) query to resolve Linear user name and email for identity linking. Follows the same pattern as fetchIssueDetails. Includes tests for success, null email, not found, and API error.
Terraform Validation Results
Pushed by: @ColeMurray, Action: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded a new exported Changes
Sequence DiagramsequenceDiagram
participant Test as Test/Caller
participant FetchUser as fetchUser
participant Client as LinearApiClient
participant LinearAPI as Linear GraphQL API
participant Logger as Logger
Test->>FetchUser: fetchUser(client, userId)
FetchUser->>Client: linearGraphQL POST (query with userId)
Client->>LinearAPI: HTTP POST
LinearAPI-->>Client: HTTP response (ok true/false + body)
Client-->>FetchUser: parsed JSON
alt GraphQL errors present
FetchUser->>Logger: log error (linear.fetch_user, user_id, Error)
FetchUser-->>Test: null
else ok true & data.user present
FetchUser->>FetchUser: normalize {id,name,email|null}
FetchUser-->>Test: {id, name, email}
else ok true & data.user null or ok false
FetchUser->>Logger: log failure
FetchUser-->>Test: null
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Summary
Adds fetchUser(client, userId) plus focused tests for the new helper. The shape is consistent with the existing Linear client helpers, but there is one blocking correctness gap in how GraphQL errors are handled.
PR Title and number: feat: add fetchUser GraphQL query to Linear client (#537)
Author: @ColeMurray
Files changed: 2, additions/deletions: +116/-0
Critical Issues
- [Functionality]
packages/linear-bot/src/utils/linear-client.ts:349- GraphQL can return200 OKwith anerrorsarray. In that caselinearGraphQL()does not throw, sofetchUser()falls through toif (!user) return null, which makes API/auth/schema failures indistinguishable from a genuine missing user and skips the intended error logging. Suggested fix: treaterrorsas a failure inlinearGraphQL()or explicitly infetchUser(), then add a test that covers a{ errors: [...] }response.
Suggestions
- [Testing]
packages/linear-bot/src/utils/linear-client.test.ts:63- Add a test for a successful HTTP response that contains a GraphQLerrorspayload. That will lock in the expected logging/failure behavior for the new helper.
Nitpicks
- None.
Positive Feedback
- The new helper stays small and follows the existing client structure, which keeps the Linear integration easy to scan.
- The tests cover the main success, nullable-email, not-found, and non-2xx failure paths.
- Using
example.comfor the email fixture keeps the test data safely synthetic.
Questions
- None.
Verdict (for GitHub PRs)
Request Changes: Critical issues must be addressed before merging.
GraphQL can return 200 OK with an errors array for auth, schema, or query failures. linearGraphQL now throws on errors payloads so all callers (fetchUser, fetchIssueDetails, etc.) get proper error logging instead of silently returning null.
|
Good catch — Addressed in e304bf2. |
Terraform Validation Results
Pushed by: @ColeMurray, Action: |
Summary
fetchUser(client, userId)tolinear-client.ts— queries Linear'suser(id:)GraphQL endpoint to resolve name and emailfetchIssueDetails: try/catch with error logging, returnsnullon failurePre-step 7 of the unified user model migration (pre-steps doc). The main migration will call
fetchUser(client, webhook.appUserId)before session creation to resolve identity for linking — having the query function already in place keeps that PR focused on wiring.Test plan
npm run typecheck -w @open-inspect/linear-botpassesnpm test -w @open-inspect/linear-bot— all 94 tests pass (90 existing + 4 new)Summary by CodeRabbit
New Features
Tests