Skip to content

fix: prevent mutation of repos array while sorting top repositories#729

Open
GaneshDeshmane wants to merge 1 commit into
AOSSIE-Org:mainfrom
GaneshDeshmane:fix/github-api-rate-limit
Open

fix: prevent mutation of repos array while sorting top repositories#729
GaneshDeshmane wants to merge 1 commit into
AOSSIE-Org:mainfrom
GaneshDeshmane:fix/github-api-rate-limit

Conversation

@GaneshDeshmane

@GaneshDeshmane GaneshDeshmane commented Jun 23, 2026

Copy link
Copy Markdown

Screenshots/Recordings:

Not applicable. This change only affects internal array handling and does not modify the UI.

Additional Notes:

This PR fixes a potential side effect caused by using Array.sort() directly on the repos array in the stats API route. The array is now copied before sorting, preserving the original data structure.

AI Usage Disclosure:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.

I have used the following AI models and tools:

  • ChatGPT (OpenAI)

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions.
  • If applicable, I have made corresponding changes or additions to the documentation.
  • If applicable, I have made corresponding changes or additions to tests.
  • 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 Contribution Guidelines.
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Description

This PR fixes an in-place mutation issue caused by Array.sort() in the stats API route.

Changes

  • Created a copy of the repos array before sorting.
  • Prevented unintended modification of the original array.

Why

Array.sort() mutates the original array. Using a copied array avoids potential side effects if repos is reused elsewhere in the code.

Testing

  • Ran the application locally.
  • Verified the /api/stats endpoint returns the expected data.
  • Confirmed no changes in API output after the fix.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue in the stats API endpoint that could inadvertently modify repository data during processing.
  • Chores

    • Updated tooling configuration to ignore deprecation warnings at a specified version threshold.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The stats API route is updated to sort a shallow copy of repos (via spread) before slicing for topRepos, preventing mutation of the original array. Additionally, jsconfig.json adds compilerOptions.ignoreDeprecations: "6.0" to suppress TypeScript 6.0 deprecation diagnostics.

Changes

Stats API and Tooling Config

Layer / File(s) Summary
Fix repos array mutation in GET /api/stats
src/app/api/stats/route.js
topRepos selection now sorts [...repos] (a shallow copy) and slices the result, instead of sorting and mutating repos in place.
Suppress TS 6.0 deprecation diagnostics
jsconfig.json
Adds compilerOptions.ignoreDeprecations set to "6.0" to silence TypeScript 6.0 deprecation warnings in tooling.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A bunny hopped in, said "please don't mutate!
Spread the array and slice — it's far more sedate."
No side effects lurking, the original's safe,
And deprecation warnings? Silenced with grace.
🐇✨ Clean code is the burrow I call home!

🚥 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 clearly and accurately summarizes the main change: preventing array mutation in the stats API route by copying the array before sorting.
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 unit tests (beta)
  • Create PR with unit tests

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.

@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.

🧹 Nitpick comments (1)
jsconfig.json (1)

4-4: 📐 Maintainability & Code Quality | 🔵 Trivial

Add a tracked removal plan for the deprecation suppression (Line 4).

The "ignoreDeprecations": "6.0" flag lacks any documented tracking (no issue, TODO, or timeline). Consider either removing it if no longer needed or adding a linked issue + deadline to ensure this technical debt doesn't accumulate silently.

🤖 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 `@jsconfig.json` at line 4, The "ignoreDeprecations": "6.0" setting in
jsconfig.json lacks any documented tracking or removal plan for this technical
debt. Either remove the "ignoreDeprecations" configuration if it is no longer
necessary, or add a comment above it with a linked GitHub issue, TODO statement,
or explicit deadline explaining why it is needed and when it should be
reassessed or removed. This ensures the deprecation suppression doesn't
accumulate as unmaintained technical debt.
🤖 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.

Nitpick comments:
In `@jsconfig.json`:
- Line 4: The "ignoreDeprecations": "6.0" setting in jsconfig.json lacks any
documented tracking or removal plan for this technical debt. Either remove the
"ignoreDeprecations" configuration if it is no longer necessary, or add a
comment above it with a linked GitHub issue, TODO statement, or explicit
deadline explaining why it is needed and when it should be reassessed or
removed. This ensures the deprecation suppression doesn't accumulate as
unmaintained technical debt.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 16f8eaa1-fb65-4d59-98a7-87e3e53892af

📥 Commits

Reviewing files that changed from the base of the PR and between 895772c and 35ce9c7.

📒 Files selected for processing (2)
  • jsconfig.json
  • src/app/api/stats/route.js

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