Skip to content

fix: strip .git suffix from normalized repository url#2116

Open
yeyuqwer wants to merge 1 commit intonpmx-dev:mainfrom
yeyuqwer:fix/strip-git-suffix-from-repository-url
Open

fix: strip .git suffix from normalized repository url#2116
yeyuqwer wants to merge 1 commit intonpmx-dev:mainfrom
yeyuqwer:fix/strip-git-suffix-from-repository-url

Conversation

@yeyuqwer
Copy link

🔗 Linked issue

#2114

🧭 Context

normalizeGitUrl does not strip the .git suffix from repository URLs. When useRepositoryUrl appends /tree/HEAD/<directory> for monorepo packages, the resulting URL contains .git in the path (e.g. https://github.com/facebook/react.git/tree/HEAD/packages/react), which leads to a 404 on GitHub.

📚 Description

Strip the .git suffix in normalizeGitUrl() during URL normalization, so downstream consumers like useRepositoryUrl produce clean, valid URLs.

The fix adds .replace(/\.git\/?$/, '') to the normalization chain in shared/utils/git-providers.ts. This is safe because each git provider's parsePath already had its own .replace(/\.git$/i, '') on the repo name — those now become no-ops.

Before: https://github.com/facebook/react.git/tree/HEAD/packages/react (404)
After: https://github.com/facebook/react/tree/HEAD/packages/react (valid)

All existing unit tests in git-providers.spec.ts continue to pass.

@vercel
Copy link

vercel bot commented Mar 17, 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 17, 2026 6:42am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Mar 17, 2026 6:42am
npmx-lunaria Ignored Ignored Mar 17, 2026 6:42am

Request Review

@codecov
Copy link

codecov bot commented Mar 17, 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!

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

This pull request modifies the git provider utilities by extending the normalizeGitUrl function to strip trailing .git or .git/ suffixes from URLs. Additionally, two utility functions (normalizeGitUrl and parseRepoUrl) are newly exported from the module. Comprehensive test coverage is added for both functions, including handling of various URL schemes (ssh, git, SCP-style, https), prefix/suffix combinations, and edge cases like empty or whitespace-only inputs.

Possibly related PRs

Suggested reviewers

  • alexdln
  • danielroe
🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description clearly explains the problem, the solution, and provides concrete examples of before/after URLs.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

CodeRabbit can enforce grammar and style rules using `languagetool`.

Configure the reviews.tools.languagetool setting to enable/disable rules and categories. Refer to the LanguageTool Community to learn more.

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 23d98de5-5e99-481a-8626-a88618deb915

📥 Commits

Reviewing files that changed from the base of the PR and between 8ee186a and 66a821c.

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

if (!raw) return null

const normalized = raw.replace(/^git\+/, '')
const normalized = raw.replace(/^git\+/, '').replace(/\.git\/?$/, '')
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Handle uppercase .GIT suffixes consistently.

The new suffix strip is case-sensitive, so values like .../repo.GIT remain unnormalised and can still break downstream repository links.

Diff
-  const normalized = raw.replace(/^git\+/, '').replace(/\.git\/?$/, '')
+  const normalized = raw.replace(/^git\+/, '').replace(/\.git\/?$/i, '')
📝 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
const normalized = raw.replace(/^git\+/, '').replace(/\.git\/?$/, '')
const normalized = raw.replace(/^git\+/, '').replace(/\.git\/?$/i, '')

@olivermrose
Copy link
Contributor

There's another open PR that fixes this #2111

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