Skip to content

Parse https github URL with branch name with slash#2

Open
Shinyaigeek wants to merge 1 commit into
pnpm:masterfrom
Shinyaigeek:feature/parse-branchname-with-slash
Open

Parse https github URL with branch name with slash#2
Shinyaigeek wants to merge 1 commit into
pnpm:masterfrom
Shinyaigeek:feature/parse-branchname-with-slash

Conversation

@Shinyaigeek

@Shinyaigeek Shinyaigeek commented Dec 31, 2022

Copy link
Copy Markdown
Member

Ticket

Refs: pnpm/pnpm#5684

Details

To support pnpm/pnpm#5684 feature, we should take two actions.

First, we should enable hosted-git-info, which pnpm uses to parse https://github.com URL, to parse github URL with branch name with slash and github URL with pull_request.
Second, we should fix pnpm itself not to reckon github URL with branch name or github URL with pull_request as tarball URL. (https://github.com/pnpm/pnpm/blob/main/resolving/tarball-resolver/src/index.ts#L33)

This Pull Request is to take the first action. Of course, we can support pnpm/pnpm#5684 without fixing hosted-git-info by arranging github URL before passing github URL into hosted-git-info in pnpm itself, but I think we should not do this because it would be more simple and better to consolidate the responsibility into git-hosted-info to parse github URL.

@Shinyaigeek

Shinyaigeek commented Dec 31, 2022

Copy link
Copy Markdown
Member Author

pnpm uses hosted-git-info forked from https://github.com/npm/hosted-git-info. so we should release forked version hosted-git-info after this PR is merged.

FYI: https://github.com/pnpm/pnpm/blob/main/package.json#L72

However, it may be better way to use original hosted-git-info in pnpm instead of forked version and send patch to original hosted-git-info...

@milahu

milahu commented Aug 13, 2023

Copy link
Copy Markdown

we should enable hosted-git-info, which pnpm uses to parse https://github.com URL, to parse github URL with branch name

or use git-url-parse instead of hosted-git-info

but probably git-url-parse fails to parse shortcuts like github:org/project and org/project

git-url-parse can parse github shortcut refs
> const GitUrlParse = require("git-url-parse");

> GitUrlParse("IonicaBizau/node-git-url-parse")
{
  protocols: [ 'https' ],
  protocol: 'https',
  port: '',
  resource: 'github.com',
  host: 'github.com',
  user: '',
  password: '',
  pathname: '/IonicaBizau/node-git-url-parse',
  hash: '',
  search: '',
  href: 'https://github.com/IonicaBizau/node-git-url-parse',
  query: {},
  parse_failed: false,
  token: '',
  toString: [Function (anonymous)],
  source: 'github.com',
  git_suffix: false,
  name: 'node-git-url-parse',
  owner: 'IonicaBizau',
  commit: undefined,
  ref: '',
  filepathtype: '',
  filepath: '',
  organization: 'IonicaBizau',
  full_name: 'IonicaBizau/node-git-url-parse'
}

> GitUrlParse("github:IonicaBizau/node-git-url-parse")
{
  protocols: [ 'github' ],
  protocol: 'github',
  port: '',
  resource: '',
  host: '',
  user: '',
  password: '',
  pathname: 'IonicaBizau/node-git-url-parse',
  hash: '',
  search: '',
  href: 'github:IonicaBizau/node-git-url-parse',
  query: {},
  parse_failed: false,
  token: '',
  toString: [Function (anonymous)],
  source: '',
  git_suffix: false,
  name: 'node-git-url-parse',
  owner: 'IonicaBizau',
  commit: undefined,
  ref: '',
  filepathtype: '',
  filepath: '',
  organization: 'IonicaBizau',
  full_name: 'IonicaBizau/node-git-url-parse'
}

but no...

git-url-parse fails to parse github branch urls and github commit urls
> const GitUrlParse = require("git-url-parse");

> GitUrlParse("https://github.com/zkochan/hosted-git-info/pull/2")
{
  protocols: [ 'https' ],
  protocol: 'https',
  port: '',
  resource: 'github.com',
  host: 'github.com',
  user: '',
  password: '',
  pathname: '/zkochan/hosted-git-info/pull/2',
  hash: '',
  search: '',
  href: 'https://github.com/zkochan/hosted-git-info/pull/2',
  query: {},
  parse_failed: false,
  token: '',
  toString: [Function (anonymous)],
  source: 'github.com',
  git_suffix: false,
  name: '2',
  owner: 'zkochan/hosted-git-info/pull',
  commit: undefined,
  ref: '',
  filepathtype: '',
  filepath: '',
  organization: 'zkochan/hosted-git-info/pull',
  full_name: 'zkochan/hosted-git-info/pull/2'
}

> GitUrlParse("https://github.com/zkochan/hosted-git-info/pull/2/commits/f0a259d0b0bea3b78e881e4497048dd8e9ab2e53")
{
  protocols: [ 'https' ],
  protocol: 'https',
  port: '',
  resource: 'github.com',
  host: 'github.com',
  user: '',
  password: '',
  pathname: '/zkochan/hosted-git-info/pull/2/commits/f0a259d0b0bea3b78e881e4497048dd8e9ab2e53',
  hash: '',
  search: '',
  href: 'https://github.com/zkochan/hosted-git-info/pull/2/commits/f0a259d0b0bea3b78e881e4497048dd8e9ab2e53',
  query: {},
  parse_failed: false,
  token: '',
  toString: [Function (anonymous)],
  source: 'github.com',
  git_suffix: false,
  name: 'f0a259d0b0bea3b78e881e4497048dd8e9ab2e53',
  owner: 'zkochan/hosted-git-info/pull/2/commits',
  commit: undefined,
  ref: '',
  filepathtype: '',
  filepath: '',
  organization: 'zkochan/hosted-git-info/pull/2/commits',
  full_name: 'zkochan/hosted-git-info/pull/2/commits/f0a259d0b0bea3b78e881e4497048dd8e9ab2e53'
}

feature request: IonicaBizau/git-url-parse#161

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