Skip to content

BackendApiClient: Include GitHub token in search and explore requests#436

Merged
rainxchzed merged 2 commits intomainfrom
impl-search-with-token
Apr 20, 2026
Merged

BackendApiClient: Include GitHub token in search and explore requests#436
rainxchzed merged 2 commits intomainfrom
impl-search-with-token

Conversation

@rainxchzed
Copy link
Copy Markdown
Member

@rainxchzed rainxchzed commented Apr 20, 2026

  • Inject TokenStore into BackendApiClient.
  • Implement currentUserGithubToken() to retrieve and trim the access token from TokenStore.
  • Add X-GitHub-Token header to search and search/explore requests if a token is available.
  • Update SharedModule to provide the TokenStore dependency to BackendApiClient.
  • Cleanup: Remove several detailed internal comments regarding language selection logic and DataStore timeouts in TweaksViewModel, TweaksRepositoryImpl, DesktopApp, and MainActivity.

Summary by CodeRabbit

  • New Features

    • Added support for GitHub authentication tokens in search requests to improve API rate limits and access to repositories.
  • Documentation

    • Removed internal comments from startup and preference initialization code.

- Inject `TokenStore` into `BackendApiClient`.
- Implement `currentUserGithubToken()` to retrieve and trim the access token from `TokenStore`.
- Add `X-GitHub-Token` header to `search` and `search/explore` requests if a token is available.
- Update `SharedModule` to provide the `TokenStore` dependency to `BackendApiClient`.
- Cleanup: Remove several detailed internal comments regarding language selection logic and DataStore timeouts in `TweaksViewModel`, `TweaksRepositoryImpl`, `DesktopApp`, and `MainActivity`.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 20, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5670f465-046a-4157-ad1a-c0b6447d406f

📥 Commits

Reviewing files that changed from the base of the PR and between 47ae608 and 30ac227.

📒 Files selected for processing (1)
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/BackendApiClient.kt

Walkthrough

Removed several explanatory comment blocks about DataStore/language-read behavior; added a TokenStore dependency to BackendApiClient and logic to fetch a GitHub token and conditionally attach an X-GitHub-Token header for search-related requests.

Changes

Cohort / File(s) Summary
Comment removals (no functional impact)
composeApp/src/androidMain/kotlin/zed/rainxch/githubstore/MainActivity.kt, composeApp/src/jvmMain/kotlin/zed/rainxch/githubstore/DesktopApp.kt, core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/TweaksRepositoryImpl.kt, feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/TweaksViewModel.kt
Removed multi-line explanatory comments about DataStore timeout/guarding and language-handling behavior; no runtime or API changes.
Token injection & header addition
core/data/src/commonMain/kotlin/zed/rainxch/core/data/di/SharedModule.kt, core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/BackendApiClient.kt
Wired TokenStore into DI for BackendApiClient; BackendApiClient constructor now accepts TokenStore. For search and searchExplore, it fetches a trimmed token (suppressing non-cancellation exceptions) and conditionally adds an X-GitHub-Token header when present.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant BackendApiClient
    participant TokenStore
    participant GitHubAPI

    Client->>BackendApiClient: search(params)
    BackendApiClient->>TokenStore: get current token
    TokenStore-->>BackendApiClient: token (or null)
    alt token present
        BackendApiClient->>GitHubAPI: HTTP GET /search (with X-GitHub-Token header)
    else no token
        BackendApiClient->>GitHubAPI: HTTP GET /search (no token header)
    end
    GitHubAPI-->>BackendApiClient: response
    BackendApiClient-->>Client: parsed result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hopped through comments, nibbled a line,
Cleared the notes so the code could shine.
I fetched a token, tucked it in flight,
Headers ready for search tonight. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 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 reflects the main functional change: adding GitHub token support to search/explore requests in BackendApiClient.

✏️ 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 impl-search-with-token

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/BackendApiClient.kt`:
- Around line 153-157: The helper currentUserGithubToken uses runCatching which
swallows CancellationException; change it to an explicit try/catch that rethrows
CancellationException and only swallows other Throwables: call
tokenStore.currentToken()?.accessToken?.trim() in a try block, if the result is
null/empty return null, catch CancellationException and rethrow it, and catch
Throwable (or Exception) to return null—this preserves structured concurrency
while keeping the original null-on-error behavior; reference
currentUserGithubToken and tokenStore.currentToken().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 27688e39-c781-4fec-9b1f-15e84b7f9c2b

📥 Commits

Reviewing files that changed from the base of the PR and between 45eaaa9 and 47ae608.

📒 Files selected for processing (6)
  • composeApp/src/androidMain/kotlin/zed/rainxch/githubstore/MainActivity.kt
  • composeApp/src/jvmMain/kotlin/zed/rainxch/githubstore/DesktopApp.kt
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/di/SharedModule.kt
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/BackendApiClient.kt
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/TweaksRepositoryImpl.kt
  • feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/TweaksViewModel.kt
💤 Files with no reviewable changes (4)
  • composeApp/src/jvmMain/kotlin/zed/rainxch/githubstore/DesktopApp.kt
  • composeApp/src/androidMain/kotlin/zed/rainxch/githubstore/MainActivity.kt
  • core/data/src/commonMain/kotlin/zed/rainxch/core/data/repository/TweaksRepositoryImpl.kt
  • feature/tweaks/presentation/src/commonMain/kotlin/zed/rainxch/tweaks/presentation/TweaksViewModel.kt

Comment thread core/data/src/commonMain/kotlin/zed/rainxch/core/data/network/BackendApiClient.kt Outdated
…BackendApiClient.kt

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@rainxchzed rainxchzed merged commit bb479d6 into main Apr 20, 2026
1 check was pending
@rainxchzed rainxchzed deleted the impl-search-with-token branch April 20, 2026 10:39
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