Skip to content

Refactor Linear API token: pass through stack instead of setting env var #590

@acreeger

Description

@acreeger

Problem

LinearService constructor sets process.env.LINEAR_API_TOKEN as a side effect (src/lib/LinearService.ts:50), and all functions in src/utils/linear.ts rely on this env var being set via getLinearApiToken()createLinearClient().

This caused a bug (#590) where il list --children called getLinearChildIssues without first instantiating LinearService, so the token was never in the environment.

Setting env vars as a side effect is fragile — any new code path that calls Linear utility functions without going through LinearService will hit the same UNAUTHORIZED error.

Desired behavior

All functions in src/utils/linear.ts should accept the API token as a parameter (with env var as fallback), passed down through the call stack. LinearService should stop setting process.env.LINEAR_API_TOKEN.

Scope

src/utils/linear.ts — Update all exported functions to accept an optional apiToken parameter and pass it to createLinearClient():

  • fetchLinearIssue
  • createLinearIssue
  • createLinearChildIssue
  • createLinearComment
  • updateLinearIssueState
  • getLinearComment
  • updateLinearComment
  • fetchLinearIssueComments
  • getLinearChildIssues (already done in Refactor Linear API token: pass through stack instead of setting env var #590)
  • createLinearIssueRelation
  • getLinearIssueDependencies
  • deleteLinearIssueRelation
  • fetchLinearIssueList (already accepts apiToken)
  • findLinearIssueRelation

src/lib/LinearService.ts — Stop setting process.env.LINEAR_API_TOKEN. Instead, store the token as an instance property and pass it to each linear.ts function call.

src/utils/image-processor.ts — Check if it reads LINEAR_API_TOKEN from env; if so, update to accept it as a parameter.

Tests — Update LinearService.test.ts to remove env var assertions. Test files that set the env var for test setup are fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions