Skip to content

fix(ui): strip .git before path/query/fragment in normalizeGitUrl#2235

Open
tinsever wants to merge 1 commit intonpmx-dev:mainfrom
tinsever:fix/issue-2233-broken-github-source-links-for-monorepo-
Open

fix(ui): strip .git before path/query/fragment in normalizeGitUrl#2235
tinsever wants to merge 1 commit intonpmx-dev:mainfrom
tinsever:fix/issue-2233-broken-github-source-links-for-monorepo-

Conversation

@tinsever
Copy link

🔗 Linked issue

Resolves #2233

🧭 Context

The package page “source” link for some monorepos pointed at URLs like https://github.com/org/repo.git/tree/HEAD/packages/..., which GitHub returns as 404. The same path without .git works. Registry metadata often uses git+https://…repo.git plus optional fragments, query strings, or a trailing slash, so stripping .git only when it was the final characters of the string was not enough.

📚 Description

  • Updated normalizeGitUrl in shared/utils/git-providers.ts to remove a .git suffix when it appears immediately before /, #, ?, or end of string (case-insensitive), not only at the absolute end of the URL.
  • Added unit tests for git+https://…repo.git#… and git+https://…repo.git?… so monorepo source links built via useRepositoryUrl (repo.url + /tree/HEAD + repository.directory) no longer embed .git in the path.

Tests: test/unit/shared/utils/git-providers.spec.ts — new expectations for fragment and query forms; existing cases still pass.

@vercel
Copy link

vercel bot commented Mar 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Mar 23, 2026 0:04am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Mar 23, 2026 0:04am
npmx-lunaria Ignored Ignored Mar 23, 2026 0:04am

Request Review

@tinsever tinsever changed the title fix(shared): strip .git before path/query/fragment in normalizeGitUrl fix(ui): strip .git before path/query/fragment in normalizeGitUrl Mar 23, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

This pull request updates the normalizeGitUrl() function to enhance how it handles trailing .git suffixes in Git repository URLs. The function previously removed .git only when it appeared exactly at the end of the URL string. The change enables removal of .git when it is followed by URL delimiters such as /, #, or ? using a case-insensitive pattern. Accompanying test cases have been added to validate the function's handling of git+https:// URLs containing fragments and query parameters.

Possibly related PRs

Suggested reviewers

  • MatteoGabriele
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The PR description clearly explains the issue, the solution, and references the linked issue #2233.
Linked Issues check ✅ Passed The code changes directly address issue #2233 by updating normalizeGitUrl to strip .git before path/query/fragment delimiters, fixing broken monorepo source links.
Out of Scope Changes check ✅ Passed All changes are scoped to the normalizeGitUrl function and its test cases, directly addressing the linked issue with no extraneous modifications.

✏️ 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 and usage tips.

Copy link
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.

🧹 Nitpick comments (1)
test/unit/shared/utils/git-providers.spec.ts (1)

41-46: Add one more regression case for .git/ path form.

These additions are solid; please also cover the slash-delimiter case from the same rule set to prevent regressions.

Suggested test addition
   expect
     .soft(normalizeGitUrl('git+https://github.com/user/repo.git?path=packages/core'))
     .toBe('https://github.com/user/repo?path=packages/core')
+  expect
+    .soft(normalizeGitUrl('git+https://github.com/user/repo.git/tree/HEAD/packages/core'))
+    .toBe('https://github.com/user/repo/tree/HEAD/packages/core')

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3fe23cee-e258-47f1-b5b9-28cef5f64213

📥 Commits

Reviewing files that changed from the base of the PR and between 1824c62 and ee124d3.

📒 Files selected for processing (2)
  • shared/utils/git-providers.ts
  • test/unit/shared/utils/git-providers.spec.ts

@codecov
Copy link

codecov bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

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.

Broken GitHub source links for monorepo packages when repository.url includes .git

1 participant