Skip to content

fix: sanitize username parameter by stripping leading @ symbol to prevent search API 422 errors - #164

Open
AbiramiR-27 wants to merge 2 commits into
AOSSIE-Org:mainfrom
AbiramiR-27:fix/contributor-profile-422
Open

fix: sanitize username parameter by stripping leading @ symbol to prevent search API 422 errors#164
AbiramiR-27 wants to merge 2 commits into
AOSSIE-Org:mainfrom
AbiramiR-27:fix/contributor-profile-422

Conversation

@AbiramiR-27

@AbiramiR-27 AbiramiR-27 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Addressed Issues:

Fixes #137

Description of Changes:

Resolves a GitHub Search API validation failure (HTTP_422 Unprocessable Entity) on the Contributor Profile dashboard.

  1. Username Sanitization: Automatically strips any leading @ symbol from the URL route username parameter before dispatcing queries, preventing query compilation crashes like q=author:@username.
  2. Fine-grained PAT Scope Fallback: If an authenticated search query fails with an HTTP_422 status (which happens when a configured fine-grained PAT lacks read permission scopes for the target organization index), the application will catch the error and automatically retry the request as a public unauthenticated call.

Screenshots/Recordings:

Resolved Profile Page Output:

image

Original Error Issue:

image image

Additional Notes:

  • Ensured the PageTitle header display format preserves the @ prefix styling natively (@username) while only cleaning it for internal queries and markdown file export names.

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved contributor profile handling by consistently recognizing usernames with or without a leading “@”.
    • Added a fallback for certain GitHub data requests when authenticated access is rejected.
    • Enhanced error messages with sanitized diagnostic details to make troubleshooting easier.
  • Improvements
    • Contributor reports, page titles, and generated filenames now use clean, consistent usernames.

@github-actions github-actions Bot added bug Something isn't working frontend Frontend changes javascript JavaScript/TypeScript changes size/M 51-200 lines changed external-contributor External contributor labels Aug 12, 2026
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@AbiramiR-27, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 41 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: fddbfd36-707d-4bbe-97e7-63a45a0dc111

📥 Commits

Reviewing files that changed from the base of the PR and between 0dd680c and 7a81949.

📒 Files selected for processing (2)
  • src/pages/ContributorProfilePage.jsx
  • src/pages/ContributorProfilePage.test.jsx

Walkthrough

Changes

Contributor profile recovery

Layer / File(s) Summary
Username normalization and output updates
src/pages/ContributorProfilePage.jsx
The page removes a leading @ from contributor usernames. The normalized value drives searches, effects, reports, filenames, titles, and lookup guards.
GitHub search fallback
src/pages/ContributorProfilePage.jsx
When authenticated searches return HTTP 422, both searches retry without authentication. Other errors keep the existing error path.
Fetch diagnostics
src/pages/ContributorProfilePage.jsx
The error panel shows sanitized and raw usernames, searched organizations, and PAT configuration status.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: Typescript Lang

Suggested reviewers: priyanshunitr, ri1tik

Poem

A rabbit trims the @ with care,
Then sends two searches through the air.
If 422 blocks the way,
No-token paths save the day.
Clear diagnostics bloom there.

🚥 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 clearly identifies the username sanitization fix and its purpose of preventing GitHub Search API HTTP 422 errors.
Linked Issues check ✅ Passed The changes address issue #137 by preventing leading-@ query errors and retrying HTTP 422 searches without authentication.
Out of Scope Changes check ✅ Passed The username normalization, retry behavior, and diagnostic details directly support the linked contributor-profile HTTP 422 fix.
✨ 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.

@github-actions github-actions Bot added size/M 51-200 lines changed and removed size/M 51-200 lines changed labels Aug 12, 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: 3

🤖 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/pages/ContributorProfilePage.jsx`:
- Line 464: Update the JSX text in the ContributorProfilePage render near
cleanUsername and username to replace both literal quotation marks with ",
preserving the displayed output and removing the no-unescaped-entities warning.
- Line 154: In the ContributorProfilePage username-handling flow, clear the
existing error state before the early return when cleanUsername is empty. Ensure
navigating to an empty contributor profile removes any previous error card
without affecting the normal fetchData path for valid usernames.
- Around line 182-203: Add regression tests for the fetch logic surrounding the
authenticated Promise.all and its catch branch: verify that HTTP_422 failures
with a PAT retry both url and mergedUrl using public headers, and that non-422
failures are rethrown without making unauthenticated requests.
🪄 Autofix

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 Plus

Run ID: e42c128c-2f1e-4f5b-ac67-1877b300d97d

📥 Commits

Reviewing files that changed from the base of the PR and between 2098d23 and 0dd680c.

📒 Files selected for processing (1)
  • src/pages/ContributorProfilePage.jsx

Comment thread src/pages/ContributorProfilePage.jsx
Comment thread src/pages/ContributorProfilePage.jsx
Comment thread src/pages/ContributorProfilePage.jsx Outdated
@github-actions github-actions Bot added tests Test changes size/M 51-200 lines changed and removed size/M 51-200 lines changed labels Aug 12, 2026
@AbiramiR-27

AbiramiR-27 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@Ri1tik ,
I have implemented the fixes for the Contributor Profile API validation error (HTTP 422). Here are the changes made:

  1. Username Sanitization: Automatically strips any leading @ character from the URL parameter, preventing invalid queries like q=author:@username from failing GitHub API search checks.
  2. Fine-grained PAT Fallback: If a configured fine-grained PAT lacks read permission scopes for the target organization index, the fetch request will catch the HTTP_422 validation error and automatically fallback to a public unauthenticated search query.
  3. Vitest Regression Tests: Created a unit test suite to verify the retry fallback behavior.

The changes are ready for your review!

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

Labels

bug Something isn't working external-contributor External contributor frontend Frontend changes javascript JavaScript/TypeScript changes size/M 51-200 lines changed tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Contributor Profile fails with HTTP 422: GitHub Search API requires is:issue or is:pull-request

1 participant