Skip to content

Refactor GitHub service for improved caching and error handling#99

Open
rudrakshtank wants to merge 2 commits into
AOSSIE-Org:mainfrom
rudrakshtank:issue98
Open

Refactor GitHub service for improved caching and error handling#99
rudrakshtank wants to merge 2 commits into
AOSSIE-Org:mainfrom
rudrakshtank:issue98

Conversation

@rudrakshtank

@rudrakshtank rudrakshtank commented Jul 3, 2026

Copy link
Copy Markdown

Addressed Issues:

Fixes #98

Checklist

  • My code follows the project's code style and conventions
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contributing Guidelines

⚠️ AI Notice - Important!

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.

Summary by CodeRabbit

  • New Features
    • Improved GitHub data fetching with better support for request cancellation.
    • Added options for authenticated requests and optional inclusion of pull requests in issue results.
  • Bug Fixes
    • Upgraded caching to be token-aware with a time-based refresh to improve consistency.
    • Enhanced handling of rate limits, authorization errors, and non-JSON responses for more predictable failures and recovery.

@github-actions github-actions Bot added enhancement New feature or request javascript JavaScript/TypeScript changes size/L 201-500 lines changed first-time-contributor First time contributor labels Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The GitHub service now uses token-aware IndexedDB caching, versioned GitHub requests, structured API error handling, and cancellation-aware fetch helpers. Public fetch functions accept an options object, and issue fetching now supports excluding pull requests by default.

Changes

GitHub fetch caching and error handling rework

Layer / File(s) Summary
IndexedDB connection and cache CRUD primitives
src/services/github.js
Caches the DB connection and adds cache get/set/delete/clear helpers with TTL checks, expiry cleanup, and write/delete failure handling.
Token fingerprinting and cache key generation
src/services/github.js
Adds fallback hashing, token fingerprinting, and token-scoped cache keys derived from the request URL and PAT state.
Request headers, rate-limit parsing, and structured errors
src/services/github.js
Sets GitHub API version and Bearer auth headers, adds tolerant JSON parsing, rate-limit header parsing, and structured error objects.
Core fetchWithCache orchestration
src/services/github.js
Combines cache lookup, network fetch, safe parsing, rate-limit updates, structured HTTP errors, and non-blocking cache writes.
Exported fetch function updates with options/signal support
src/services/github.js
Updates the exported fetch helpers to accept options, pass through signal, adjust repo pagination, and filter pull requests from issue results by default.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant fetchWithCache as fetchWithCache
  participant IndexedDB as IndexedDB cache
  participant GitHubAPI as GitHub API
  participant Window as window

  fetchWithCache->>IndexedDB: read token-scoped cached response
  fetchWithCache->>GitHubAPI: request with Bearer auth and API version
  GitHubAPI-->>fetchWithCache: response and rate-limit headers
  fetchWithCache->>Window: dispatch rate-limit update
  fetchWithCache->>IndexedDB: store successful response asynchronously
Loading

Possibly related PRs

  • AOSSIE-Org/OrgExplorer#89: Modifies the same GitHub fetch helpers, including PAT-aware pagination and exported fetch behavior.
  • AOSSIE-Org/OrgExplorer#115: Also changes fetchContributors and fetchIssues behavior in src/services/github.js, overlapping with the updated fetch flow.

Suggested labels: Typescript Lang

Suggested reviewers: Zahnentferner, bhavik-mangla, rahul-vyas-dev

Poem

A rabbit built a burrow of bytes,
With token keys and cache-light nights.
It hopped through headers, swift and neat,
Spotted rate limits, stayed on beat,
Then nibbled JSON, warm and bright.

🚥 Pre-merge checks | ✅ 4
✅ 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 is concise and accurately summarizes the GitHub service caching and error-handling refactor.
Linked Issues check ✅ Passed The changes implement IndexedDB caching, TTL, cache reads and writes, PAT auth, rate-limit updates, and shared fetch logic as requested.
Out of Scope Changes check ✅ Passed The changes stay focused on GitHub API fetching, caching, auth, rate limits, and error handling with no clear unrelated scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Biome (2.5.1)
src/services/github.js

File contains syntax errors that prevent linting: Line 358: Illegal use of an export declaration not at the top level; Line 376: expected } but instead the file ends; Line 330: Illegal use of an export declaration not at the top level; Line 376: expected } but instead the file ends


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.

@github-actions github-actions Bot added size/L 201-500 lines changed and removed size/L 201-500 lines changed labels Jul 3, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/github.js`:
- Around line 28-35: The IndexedDB connection cached by dbPromise is not being
reset when db.onversionchange closes the database, so later cacheGet/cacheSet
calls keep reusing a closed handle and fail. Update the db.onversionchange
handler in the open DB flow to clear dbPromise before closing the db, so the
next cache access in the GitHub service opens a fresh connection instead of
reusing the stale one.
🪄 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: ASSERTIVE

Plan: Pro

Run ID: 182a475a-ff65-4f11-914e-9c2937ddd5b5

📥 Commits

Reviewing files that changed from the base of the PR and between d904719 and 876af9b.

📒 Files selected for processing (1)
  • src/services/github.js

Comment thread src/services/github.js
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

⚠️ This PR has merge conflicts.

Please resolve the merge conflicts before review.

Your PR will only be reviewed by a maintainer after all conflicts have been resolved.

📺 Watch this video to understand why conflicts occur and how to resolve them:
https://www.youtube.com/watch?v=Sqsz1-o7nXk

@github-actions github-actions Bot added size/L 201-500 lines changed and removed PR has merge conflicts size/L 201-500 lines changed labels Jul 8, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/github.js`:
- Around line 314-316: Remove the stale unbounded pagination header from both
helpers so only the bounded loop remains; in fetchContributors and fetchIssues,
keep the maxPages-based for (let page = 1; page <= maxPages; page++) form and
delete the leftover for (let page = 1; ; page++) line that leaves an extra open
block and breaks the file.
- Around line 338-340: Remove the stale outer pagination loop in fetchIssues and
keep only the bounded page loop driven by maxPages. Update the control flow
around the pagination logic in fetchIssues so there is a single, properly braced
for-loop using page and maxPages, with no nested infinite loop remaining.
🪄 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: ASSERTIVE

Plan: Pro

Run ID: 790b873f-3ead-4903-8bf8-b0cc663bc923

📥 Commits

Reviewing files that changed from the base of the PR and between 876af9b and f8fdbcd.

📒 Files selected for processing (1)
  • src/services/github.js

Comment thread src/services/github.js
Comment on lines +314 to 316
for (let page = 1; ; page++) {
const maxPages = pat ? 10 : 1
for(let page = 1; page<=maxPages ; page++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm the leftover loop header and brace balance in the two helpers.
rg -nP 'for\s*\(let page' src/services/github.js
node -e "require('fs').readFileSync('src/services/github.js','utf8')" 2>&1 | head -5 || true

Repository: AOSSIE-Org/OrgExplorer

Length of output: 389


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- surrounding lines ---'
sed -n '306,346p' src/services/github.js | cat -n

echo
echo '--- syntax check ---'
node --check src/services/github.js 2>&1 || true

Repository: AOSSIE-Org/OrgExplorer

Length of output: 1716


Remove the duplicated pagination headers in both helpers.

fetchContributors and fetchIssues still keep the old for (let page = 1; ; page++) line above the new bounded loop, which leaves an extra open block and breaks the file. Keep only the bounded for (let page = 1; page <= maxPages; page++) form in both places.

Proposed fix
-  for (let page = 1; ; page++) {
-  const maxPages = pat ? 10 : 1
-  for(let page = 1; page<=maxPages ; page++) {
+  const maxPages = pat ? 10 : 1
+  for (let page = 1; page <= maxPages; page++) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for (let page = 1; ; page++) {
const maxPages = pat ? 10 : 1
for(let page = 1; page<=maxPages ; page++) {
const maxPages = pat ? 10 : 1
for (let page = 1; page <= maxPages; page++) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/github.js` around lines 314 - 316, Remove the stale unbounded
pagination header from both helpers so only the bounded loop remains; in
fetchContributors and fetchIssues, keep the maxPages-based for (let page = 1;
page <= maxPages; page++) form and delete the leftover for (let page = 1; ;
page++) line that leaves an extra open block and breaks the file.

Comment thread src/services/github.js
Comment on lines +338 to 340
for (let page = 1; ; page++) {
const maxPages = pat ? 10 : 1
for(let page = 1; page<=maxPages ; page++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Remove the stale outer pagination loop in fetchIssues. The bounded loop already handles paging, so keeping for (let page = 1; ; page++) creates nested loops and leaves the braces unbalanced.

Proposed fix
-  for (let page = 1; ; page++) {
-  const maxPages = pat ? 10 : 1
-  for(let page = 1; page<=maxPages ; page++) {
+  const maxPages = pat ? 10 : 1
+  for (let page = 1; page <= maxPages; page++) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/github.js` around lines 338 - 340, Remove the stale outer
pagination loop in fetchIssues and keep only the bounded page loop driven by
maxPages. Update the control flow around the pagination logic in fetchIssues so
there is a single, properly braced for-loop using page and maxPages, with no
nested infinite loop remaining.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

⚠️ This PR has merge conflicts.

Please resolve the merge conflicts before review.

Your PR will only be reviewed by a maintainer after all conflicts have been resolved.

📺 Watch this video to understand why conflicts occur and how to resolve them:
https://www.youtube.com/watch?v=Sqsz1-o7nXk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request first-time-contributor First time contributor javascript JavaScript/TypeScript changes PR has merge conflicts size/L 201-500 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Improved GitHub API Fetching with IndexedDB Caching

1 participant