Skip to content

hosted-git-info truncates SSH repository names containing dots #51

Description

@davidsneighbour

Summary

@simple-libs/hosted-git-info@1.0.2 truncates SSH repository names that contain dots.

For example, git@github.com:davidsneighbour/kollitsch.dev.git is parsed as davidsneighbour/kollitsch instead of davidsneighbour/kollitsch.dev.

Reproduction

import { parseHostedGitUrl } from "@simple-libs/hosted-git-info";

const cases = [
  "git@github.com:davidsneighbour/kollitsch.dev.git",
  "git@github.com:davidsneighbour/kollitsch.dev",
  "git@github.com:davidsneighbour/foo.bar.git",
  "https://github.com/davidsneighbour/kollitsch.dev.git",
  "https://github.com/davidsneighbour/kollitsch.dev",
];

for (const input of cases) {
  console.log(input, parseHostedGitUrl(input));
}

Actual result

parseHostedGitUrl("git@github.com:davidsneighbour/kollitsch.dev.git")
// {
//   url: "https://github.com/davidsneighbour/kollitsch",
//   type: "github",
//   host: "https://github.com",
//   owner: "davidsneighbour",
//   project: "kollitsch"
// }

parseHostedGitUrl("git@github.com:davidsneighbour/foo.bar.git")
// {
//   url: "https://github.com/davidsneighbour/foo",
//   type: "github",
//   host: "https://github.com",
//   owner: "davidsneighbour",
//   project: "foo"
// }

Expected result

parseHostedGitUrl("git@github.com:davidsneighbour/kollitsch.dev.git")
// {
//   url: "https://github.com/davidsneighbour/kollitsch.dev",
//   type: "github",
//   host: "https://github.com",
//   owner: "davidsneighbour",
//   project: "kollitsch.dev"
// }

parseHostedGitUrl("git@github.com:davidsneighbour/foo.bar.git")
// {
//   url: "https://github.com/davidsneighbour/foo.bar",
//   type: "github",
//   host: "https://github.com",
//   owner: "davidsneighbour",
//   project: "foo.bar"
// }

Notes

This appears to come from the project capture groups excluding dots, for example ([^/.#]+). In the SSH URL branch, the expression also does not appear to be anchored to the end of the input, so .dev.git is effectively discarded.

HTTPS URLs keep the full path in url, but do not populate owner and project for dotted repository names:

parseHostedGitUrl("https://github.com/davidsneighbour/kollitsch.dev.git")
// {
//   url: "https://github.com/davidsneighbour/kollitsch.dev",
//   type: "github",
//   host: "https://github.com"
// }

Downstream impact

This surfaced through @release-it/conventional-changelog, via conventional-changelog, when release notes were generated from a repository whose remote is:

git@github.com:davidsneighbour/kollitsch.dev.git

The generated changelog and GitHub release links pointed to:

https://github.com/davidsneighbour/kollitsch

instead of:

https://github.com/davidsneighbour/kollitsch.dev

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions