Skip to content

fix: refresh token when importing#107

Merged
gfyrag merged 1 commit intomainfrom
fix/token-refresh-when-importing
Jan 23, 2026
Merged

fix: refresh token when importing#107
gfyrag merged 1 commit intomainfrom
fix/token-refresh-when-importing

Conversation

@gfyrag
Copy link
Contributor

@gfyrag gfyrag commented Jan 23, 2026

No description provided.

@gfyrag gfyrag requested a review from a team as a code owner January 23, 2026 11:01
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 23, 2026

Walkthrough

The token management flow in NewStackClient is refactored to use a refresh-aware token source. Instead of a one-shot fetch, NewStackTokenSource is now initialized with an onRefresh callback that automatically persists refreshed tokens via WriteStackToken, enabling dynamic token lifecycle management.

Changes

Cohort / File(s) Summary
Token Source Initialization
pkg/clients.go
Updated NewStackClient to instantiate NewStackTokenSource with an onRefresh callback instead of using a direct StaticTokenSource. The callback writes refreshed tokens to persistence layer, introducing automatic token lifecycle management. Function signature modified to accept onRefresh callback parameter.

Sequence Diagram(s)

sequenceDiagram
    actor Client
    participant NewStackClient
    participant NewStackTokenSource
    participant oauth2 as oauth2.TokenSource
    participant WriteStackToken

    Client->>NewStackClient: Initialize
    NewStackClient->>NewStackTokenSource: Create with stackToken, stackAccess, onRefresh callback
    NewStackTokenSource-->>NewStackClient: Token Source ready
    
    Client->>oauth2: Request token
    oauth2->>NewStackTokenSource: Get token (may refresh)
    alt Token expired
        NewStackTokenSource->>NewStackTokenSource: Refresh token
        NewStackTokenSource->>WriteStackToken: onRefresh(newToken)
        WriteStackToken-->>NewStackTokenSource: Token persisted
    end
    NewStackTokenSource-->>oauth2: Return token
    oauth2-->>Client: Token available
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Token refresh now flows like clover's gentle bloom,
With callbacks whispered soft through digital rooms,
No stale keys linger when new ones appear—
Persistence and grace throughout the long year! 🌿

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
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.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess relevance to the changeset. Add a description explaining the purpose of the token refresh mechanism, why it's needed during import, and any relevant context or motivation for this change.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: refresh token when importing' clearly summarizes the main change: implementing token refresh functionality during import operations.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/token-refresh-when-importing

Comment @coderabbitai help to get the list of available commands and usage tips.

@gfyrag gfyrag merged commit 415f4eb into main Jan 23, 2026
3 of 4 checks passed
@gfyrag gfyrag deleted the fix/token-refresh-when-importing branch January 23, 2026 15:27
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.

2 participants