Skip to content

feat: add fetchUser GraphQL query to Linear client#537

Merged
ColeMurray merged 2 commits intomainfrom
pre-step-7/linear-fetchUser-query
Apr 22, 2026
Merged

feat: add fetchUser GraphQL query to Linear client#537
ColeMurray merged 2 commits intomainfrom
pre-step-7/linear-fetchUser-query

Conversation

@ColeMurray
Copy link
Copy Markdown
Owner

@ColeMurray ColeMurray commented Apr 22, 2026

Summary

  • Adds fetchUser(client, userId) to linear-client.ts — queries Linear's user(id:) GraphQL endpoint to resolve name and email
  • Follows the same pattern as fetchIssueDetails: try/catch with error logging, returns null on failure
  • Includes 4 tests: success with email, null email, user not found, API error

Pre-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-bot passes
  • npm test -w @open-inspect/linear-bot — all 94 tests pass (90 existing + 4 new)

Summary by CodeRabbit

  • New Features

    • Added user retrieval from Linear with normalized {id, name, email|null} responses and safe error handling that returns null on failure.
  • Tests

    • Added thorough tests for user retrieval covering success, null fields, missing user, network errors, and GraphQL errors; tests isolate and restore global fetch between cases.

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.
@github-actions
Copy link
Copy Markdown

Terraform Validation Results

Step Status
Format
Init
Validate

Note: Terraform plan was skipped because secrets are not configured. This is expected for external contributors. See docs/GETTING_STARTED.md for setup instructions.

Pushed by: @ColeMurray, Action: pull_request

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a892972e-7bc4-4d6b-94e7-f11e3759ef12

📥 Commits

Reviewing files that changed from the base of the PR and between 23c4175 and e304bf2.

📒 Files selected for processing (2)
  • packages/linear-bot/src/utils/linear-client.test.ts
  • packages/linear-bot/src/utils/linear-client.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/linear-bot/src/utils/linear-client.test.ts

📝 Walkthrough

Walkthrough

Added a new exported fetchUser function to query Linear's GraphQL API for a user by ID, with explicit GraphQL error checks, try/catch logging, and normalized output ({ id, name, email | null } | null). Also added Vitest tests covering success and multiple error cases.

Changes

Cohort / File(s) Summary
New fetchUser Implementation
packages/linear-bot/src/utils/linear-client.ts
Added fetchUser(client, userId) performing a GraphQL user(id:$id) query, parses JSON, throws on GraphQL errors, returns normalized `{ id, name, email: string
fetchUser Test Suite
packages/linear-bot/src/utils/linear-client.test.ts
Added Vitest suite with vi.stubGlobal("fetch", ...), clearing mocks between tests and un-stubbing globals. Tests cover: success with email, success with null email, user: null, non-OK HTTP response, and GraphQL errors response.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • open-inspect

Poem

🐰 I hopped to fetch a user's name,
Through GraphQL fields and error flame.
Tests snug in a tidy row,
Logs to catch what winds may blow,
Data returned—simple and tame. 🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main change: adding a new fetchUser GraphQL query function to the Linear client, which is the primary focus of this pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pre-step-7/linear-fetchUser-query

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.

open-inspect[bot]
open-inspect Bot previously requested changes Apr 22, 2026
Copy link
Copy Markdown
Contributor

@open-inspect open-inspect Bot left a comment

Choose a reason for hiding this comment

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

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 return 200 OK with an errors array. In that case linearGraphQL() does not throw, so fetchUser() falls through to if (!user) return null, which makes API/auth/schema failures indistinguishable from a genuine missing user and skips the intended error logging. Suggested fix: treat errors as a failure in linearGraphQL() or explicitly in fetchUser(), 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 GraphQL errors payload. 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.com for 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.
@ColeMurray
Copy link
Copy Markdown
Owner Author

Good catch — linearGraphQL only checked HTTP status, so GraphQL-level errors (auth, schema, etc. returning 200 OK with { errors: [...] }) silently fell through for all callers, not just fetchUser. Fixed in linearGraphQL itself so every caller benefits: it now throws when the response contains an errors array. Added a test for the { errors: [...] } case.

Addressed in e304bf2.

@github-actions
Copy link
Copy Markdown

Terraform Validation Results

Step Status
Format
Init
Validate

Note: Terraform plan was skipped because secrets are not configured. This is expected for external contributors. See docs/GETTING_STARTED.md for setup instructions.

Pushed by: @ColeMurray, Action: pull_request

@ColeMurray ColeMurray merged commit 5f4dcbe into main Apr 22, 2026
18 checks passed
@ColeMurray ColeMurray deleted the pre-step-7/linear-fetchUser-query branch April 22, 2026 06:50
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