Skip to content

Detect GitHub and GitLab SSH repository URLs when rewriting README links - #1362

Draft
Federico Brancasi (federicobrancasi) wants to merge 4 commits into
mainfrom
fbrancasi/ssh-repository-urls
Draft

Federico Brancasi (federicobrancasi) wants to merge 4 commits into
mainfrom
fbrancasi/ssh-repository-urls

Conversation

@federicobrancasi

@federicobrancasi Federico Brancasi (federicobrancasi) commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

When package.json uses an SSH repository URL, such as "repository": { "type": "git", "url": "[email protected]:owner/repo.git" }, vsce package doesn't recognize the repository as GitHub. If the README has a relative image like ![demo](images/demo.gif), packaging fails with "Couldn't detect the repository where this extension is published. The image 'images/demo.gif' will be broken in README.md. GitHub/GitLab repositories will be automatically detected...", even though the repository is on GitHub. Without relative links, #123 issue references are not turned into links. GitLab URLs like [email protected]:group/project.git have the same problem. The cause is guessBaseUrls: its regexes only accept github.com/ or github: (and the same for GitLab), so they miss the github.com: separator. The Marketplace links in the same package already handle this URL form correctly, because ManifestProcessor reads it with hosted-git-info, and isGitHubRepository also expects [email protected]:.

This PR lets the GitHub and GitLab regexes in guessBaseUrls also accept .com:, so SSH URLs get the same https://github.com/owner/repo/blob/HEAD (or GitLab) base URLs as HTTPS URLs. The port of a URL with a scheme, as in ssh://[email protected]:22/owner/repo.git, is dropped before matching instead of being read as the owner, while a numeric namespace in an SCP-like URL, as in [email protected]:123/group/project.git, is kept. Hosts that only end with github or gitlab, like [email protected]:owner/repo.git, are not taken for GitHub or GitLab.

How to test

Command Result
npx mocha --grep "ssh format" 3 passing; the new tests "should infer baseContentUrl if its a github repo (ssh format)", "should infer baseContentUrl if its a gitlab repo (ssh format)" and "should infer baseContentUrl if its a gitlab repo with a numeric namespace (ssh format)" fail without the change
npx mocha --grep "host that only ends" 1 passing; the new test "should not replace issue links with urls if its an ssh url of a host that only ends with github or gitlab" fails without the host check
npm test 409 passing, 5 pending; 4 collect tests fail before and after the change only because yarn is not installed on this machine
npx tsc --noEmit --typeRoots ./node_modules/@types passes

When `package.json` uses an SSH repository URL, such as `"repository": { "type": "git", "url": "[email protected]:owner/repo.git" }`, `vsce package` doesn't recognize the repository as GitHub. If the README has a relative image like `![demo](images/demo.gif)`, packaging fails with "Couldn't detect the repository where this extension is published. The image 'images/demo.gif' will be broken in README.md. GitHub/GitLab repositories will be automatically detected...", even though the repository is on GitHub. Without relative links, `#123` issue references are not turned into links. GitLab URLs like `[email protected]:group/project.git` have the same problem. The cause is `guessBaseUrls`: its regexes only accept `github.com/` or `github:` (and the same for GitLab), so they miss the `github.com:` separator. The Marketplace links in the same package already handle this URL form correctly, because `ManifestProcessor` reads it with `hosted-git-info`, and `isGitHubRepository` also expects `[email protected]:`.

Co-authored-by: Copilot <[email protected]>

Copilot AI 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.

🟡 Changes recommended

Scheme-based GitHub and GitLab URLs with explicit ports are parsed as incorrect repository paths, silently rewriting Markdown and issue links to the wrong repository.

1 open issue
What changed in this PR

Adds support for SCP-style SSH repository URLs in vsce’s Markdown processing, enabling automatic GitHub and GitLab URL inference for relative links, images, and issue references.

Changes:

  • Extends repository detection to accept github.com: and gitlab.com: separators.
  • Adds README regression tests for both providers’ SSH URL formats.
File Description
src/​test/​package.test.ts Adds SSH repository URL tests for GitHub and GitLab.
src/​package.ts Extends repository-matching expressions to recognize SCP-style SSH URLs.

Review effort: Balanced

Comment thread src/package.ts Resolved
`ssh://[email protected]:22/owner/repo.git` matched `github.com:` and gave the project `22/owner`. Allow a port before the path, and test both URL forms for GitHub and GitLab.

Co-authored-by: Copilot <[email protected]>

Copilot AI 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.

🟡 Changes recommended

The regex misinterprets a numeric namespace in SCP-style GitLab URLs as a port, causing README, changelog, and issue links to target the wrong project.

2 open issues

Review effort: Balanced

Comment thread src/package.ts Resolved
`[email protected]:123/subgroup/project.git` matched `gitlab.com:123/` as a host with a port and gave the project `subgroup/project`. Drop the port only from URLs with a scheme, before matching, and test a numeric namespace in both URL forms.

Co-authored-by: Copilot <[email protected]>

Copilot AI 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.

🔵 Needs a closer look

Unanchored repository patterns misclassify SSH hosts such as mygithub.com and mygitlab.com, silently rewriting documentation links and issue references to the wrong hosts.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Anchor GitHub and GitLab hostname matches

src/​package.ts:985

The unanchored patterns now accept [email protected]:owner/repo.git and [email protected]:group/project.git as public GitHub/GitLab repositories. This silently rewrites relative README/changelog links and issue references to the wrong hosts. Match the complete hostname in both patterns, preserve the supported URL and shorthand forms, and add negative SSH-host regression tests.

2 resolved since last review

Review effort: Balanced

With the SSH form, `[email protected]:owner/repo.git` and `[email protected]:group/project.git` were taken for GitHub and GitLab repositories, so README links and issue references pointed to the wrong host. Require that `github`/`gitlab` isn't preceded by a letter, digit, `_` or `-`, and test both hosts.

Co-authored-by: Copilot <[email protected]>

Copilot AI 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.

🔵 Needs a closer look

Human assessment is needed because provider-host matching can misidentify dotted mirror domains and rewrite README/changelog links and issue references to the wrong host.

No open issues 🎉

Review effort: Balanced

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