Skip to content

fix: improve normalizeGitUrl#2113

Open
bluwy wants to merge 5 commits intonpmx-dev:mainfrom
bluwy:improve-normalizeGitUrl
Open

fix: improve normalizeGitUrl#2113
bluwy wants to merge 5 commits intonpmx-dev:mainfrom
bluwy:improve-normalizeGitUrl

Conversation

@bluwy
Copy link
Contributor

@bluwy bluwy commented Mar 17, 2026

🔗 Linked issue

fix #2097

🧭 Context

Ok so, that linked issue already has two PRs, I'm submitting another 😅 This PR uses a function that I've used in publint (and tested), and also copied to vite, which has been working well, so it might be useful to reuse the same code here.

EDIT: Looks like the code didn't handle radicle urls properly (https://app.radicle.at/nodes/seed.radicle.at/rad:z3nP4yT1PE3m1PxLEzr173sZtJVnT, the colon) but I've updated to handle it, downside of copying snippets I guess 😬

📚 Description

This PR introduces a simpler git url normalization code and handles the trailing .git bug.

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

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f1f56b26-d32f-49cd-bac1-6c5144ffb00c

📥 Commits

Reviewing files that changed from the base of the PR and between f443ecd and 48fb4e8.

📒 Files selected for processing (1)
  • shared/utils/git-providers.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • shared/utils/git-providers.ts

📝 Walkthrough

Walkthrough

This pull request updates repository URL handling in two places. shared/utils/git-providers.ts replaces the previous multi-branch normalization with a single-pass normalizeGitUrl that trims input, removes git+, strips a trailing .git, removes user@ from SSH-like inputs, converts host:port separators to /, normalises git:// and ssh:// to https://, ensures a scheme (prefixing https:// if missing) and returns null for empty results. app/composables/useRepositoryUrl.ts adds a defensive early return to return null when normalizeGitUrl yields a falsy value, preventing further URL augmentation.

Possibly related PRs

Suggested reviewers

  • danielroe
  • alexdln
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The PR description is directly related to the changeset, referencing issue #2097 and explaining the git URL normalization improvements and trailing .git bug fix.
Linked Issues check ✅ Passed The PR addresses issue #2097 by fixing the git URL normalization to remove trailing .git before appending paths, preventing GitHub 404 errors when accessing repository links.
Out of Scope Changes check ✅ Passed All changes are within scope: useRepositoryUrl.ts adds defensive early return for invalid URLs, and git-providers.ts simplifies normalizeGitUrl to fix the trailing .git bug reported in issue #2097.

✏️ 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.

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: 668114a4-b18a-44e2-b608-0195545392e1

📥 Commits

Reviewing files that changed from the base of the PR and between c5202d0 and f7decab.

📒 Files selected for processing (2)
  • app/composables/useRepositoryUrl.ts
  • shared/utils/git-providers.ts

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

♻️ Duplicate comments (1)
shared/utils/git-providers.ts (1)

301-303: ⚠️ Potential issue | 🔴 Critical

Preserve explicit SSH ports; current rewrite breaks valid remotes.

Line 301 rewrites host:port into host/port, so URLs like ssh://git@gitlab.example.com:2222/group/repo.git are malformed and parsed incorrectly.

Proposed fix
 export function normalizeGitUrl(input: string): string | null {
   let url = input
     .trim()
     .replace(/^git\+/, '')
     .replace(/\.git$/, '')
-    .replace(/(^|\/)[^/]+?@/, '$1') // remove "user@" from "ssh://user@host.com:..."
-    .replace(/(\.[^./]+?):/, '$1/') // change ".com:" to ".com/" from "ssh://user@host.com:..."
+  if (!url) return null
+
+  // SCP-style: git@host:owner/repo -> https://host/owner/repo
+  if (/^[^@/\s]+@[^:/\s]+:.+/.test(url)) {
+    url = url.replace(/^[^@/\s]+@([^:/\s]+):/, 'https://$1/')
+  } else {
+    // URL-style: remove optional userinfo only
+    url = url.replace(/(^|\/\/)[^/@]+@/, '$1')
+  }
+
+  // Only rewrite host:path when no scheme exists (avoid touching :port)
+  if (!url.includes('://')) {
+    url = url.replace(/(\.[^./]+?):/, '$1/')
+  }
+
+  url = url
     .replace(/^git:\/\//, 'https://')
     .replace(/^ssh:\/\//, 'https://')
   url = url.includes('://') ? url : `https://${url}`
   return url || null
 }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2f46b42b-2208-4bfc-a7a2-009fc7c75efc

📥 Commits

Reviewing files that changed from the base of the PR and between f7decab and f443ecd.

📒 Files selected for processing (1)
  • shared/utils/git-providers.ts

@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
app/composables/useRepositoryUrl.ts 50.00% 1 Missing ⚠️

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

Github Link redirects to Github 404 page

1 participant