Skip to content

🛠️ DX: Add smart user URL parsing - #220

Open
bartholomej wants to merge 1 commit into
masterfrom
dx-smart-user-url-parsing-9572647608027139898
Open

🛠️ DX: Add smart user URL parsing#220
bartholomej wants to merge 1 commit into
masterfrom
dx-smart-user-url-parsing-9572647608027139898

Conversation

@bartholomej

@bartholomej bartholomej commented Aug 6, 2026

Copy link
Copy Markdown
Owner

💡 What: Introduced a new extractUser helper inside global.helper.ts to flexibly handle full ČSFD URLs, slugs, or numeric IDs for users. Integrated it seamlessly into the UserRatingsScraper and UserReviewsScraper services.

🎯 Why: Developers often have a full URL (e.g. from a scraper or a frontend input) but previously had to manually extract the exact slug or ID before passing it to the library. Now, the library magically extracts it, dramatically reducing boilerplate and providing a smoother Developer Experience.

🚀 Examples:

// ❌ Before
const userSlug = parseMyUrl('https://www.csfd.cz/uzivatel/912-bart/');
const ratings = await csfd.userRatings(userSlug);

// ✅ After
const ratings = await csfd.userRatings('https://www.csfd.cz/uzivatel/912-bart/');

PR created automatically by Jules for task 9572647608027139898 started by @bartholomej

Summary by CodeRabbit

  • New Features
    • Added support for identifying users by numeric ID, username slug, or full profile URL.
    • User references are automatically trimmed and normalized before retrieving ratings or reviews.
  • Bug Fixes
    • Improved ratings and reviews retrieval when using profile URLs or language-prefixed URLs.
    • Invalid, unsupported, or empty user references now return a clear validation error instead of producing incorrect requests.

…and full URLs

Co-authored-by: bartholomej <5861310+bartholomej@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds extractUser to normalize user IDs, slugs, and user URLs. The ratings and reviews services validate inputs and use the normalized value for initial and paginated requests. Tests cover valid and invalid extraction inputs.

Changes

User identifier normalization

Layer / File(s) Summary
Add and test user extraction
src/helpers/global.helper.ts, tests/helpers.test.ts
Adds extractUser for numeric IDs, slugs, and user URLs. Invalid and unsupported inputs return null. Tests cover these cases.
Normalize ratings and reviews requests
src/services/user-ratings.service.ts, src/services/user-reviews.service.ts
Both services validate user input and use the normalized identifier for initial and paginated requests.

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

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and motivation but omits the required Type of change, Related Issues, and Checklist sections. Add the required template sections and complete the applicable type, issue, self-review, warning, and test checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding smart parsing for user URLs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 dx-smart-user-url-parsing-9572647608027139898

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.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.21%. Comparing base (4e9623e) to head (d10b07b).

Files with missing lines Patch % Lines
src/helpers/global.helper.ts 92.85% 1 Missing ⚠️
src/services/user-ratings.service.ts 80.00% 1 Missing ⚠️
src/services/user-reviews.service.ts 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #220      +/-   ##
==========================================
- Coverage   98.46%   98.21%   -0.26%     
==========================================
  Files          39       39              
  Lines        1045     1065      +20     
  Branches      244      252       +8     
==========================================
+ Hits         1029     1046      +17     
- Misses         16       19       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@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/helpers/global.helper.ts`:
- Around line 66-70: Update the URL parsing logic around the helper’s trimmed
URL handling to remove the query string and fragment before splitting or
searching for the uzivatel path segment. Ensure identifiers never include query
or fragment data and URLs whose query or fragment merely contains /uzivatel/ are
not accepted; add regression tests covering both cases.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 335e519a-1f8f-43fe-b64b-169d65e75ff6

📥 Commits

Reviewing files that changed from the base of the PR and between 4e9623e and d10b07b.

📒 Files selected for processing (4)
  • src/helpers/global.helper.ts
  • src/services/user-ratings.service.ts
  • src/services/user-reviews.service.ts
  • tests/helpers.test.ts

Comment on lines +66 to +70
if (trimmed.includes('/') || trimmed.includes('csfd.')) {
const parts = trimmed.split('/');
const uzivatelIndex = parts.indexOf('uzivatel');
if (uzivatelIndex !== -1 && parts[uzivatelIndex + 1]) {
return parts[uzivatelIndex + 1];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Parse only the URL path.

Line 67 splits the complete URL. A query string or fragment can contain /uzivatel/ and be accepted as a user URL. For example, a film URL with ?next=/uzivatel/912-bart returns 912-bart.

A user URL with query parameters also returns an identifier that contains ?, which creates an invalid request URL. Strip the query and fragment before splitting. Add a regression test for both cases.

Proposed fix
-    if (trimmed.includes('/') || trimmed.includes('csfd.')) {
-      const parts = trimmed.split('/');
+    const path = trimmed.replace(/[?#].*$/, '');
+    if (path.includes('/') || path.includes('csfd.')) {
+      const parts = path.split('/');
📝 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
if (trimmed.includes('/') || trimmed.includes('csfd.')) {
const parts = trimmed.split('/');
const uzivatelIndex = parts.indexOf('uzivatel');
if (uzivatelIndex !== -1 && parts[uzivatelIndex + 1]) {
return parts[uzivatelIndex + 1];
const path = trimmed.replace(/[?#].*$/, '');
if (path.includes('/') || path.includes('csfd.')) {
const parts = path.split('/');
const uzivatelIndex = parts.indexOf('uzivatel');
if (uzivatelIndex !== -1 && parts[uzivatelIndex + 1]) {
return parts[uzivatelIndex + 1];
🤖 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/helpers/global.helper.ts` around lines 66 - 70, Update the URL parsing
logic around the helper’s trimmed URL handling to remove the query string and
fragment before splitting or searching for the uzivatel path segment. Ensure
identifiers never include query or fragment data and URLs whose query or
fragment merely contains /uzivatel/ are not accepted; add regression tests
covering both cases.

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