Code Monkey home page Code Monkey logo

git-url-parse's Introduction

git-url-parse

git-url-parse

Support me on Patreon Buy me a book PayPal Ask me anything Travis Version Downloads Get help on Codementor

Buy Me A Coffee

A high level git url parser for common git providers.

☁️ Installation

# Using npm
npm install --save git-url-parse

# Using yarn
yarn add git-url-parse

πŸ“‹ Example

// Dependencies
const GitUrlParse = require("git-url-parse");

console.log(GitUrlParse("[email protected]:IonicaBizau/node-git-url-parse.git"));
// => {
//     protocols: []
//   , port: null
//   , resource: "github.com"
//   , user: "git"
//   , pathname: "/IonicaBizau/node-git-url-parse.git"
//   , hash: ""
//   , search: ""
//   , href: "[email protected]:IonicaBizau/node-git-url-parse.git"
//   , token: ""
//   , protocol: "ssh"
//   , toString: [Function]
//   , source: "github.com"
//   , name: "node-git-url-parse"
//   , owner: "IonicaBizau"
// }

console.log(GitUrlParse("https://github.com/IonicaBizau/node-git-url-parse.git"));
// => {
//     protocols: ["https"]
//   , port: null
//   , resource: "github.com"
//   , user: ""
//   , pathname: "/IonicaBizau/node-git-url-parse.git"
//   , hash: ""
//   , search: ""
//   , href: "https://github.com/IonicaBizau/node-git-url-parse.git"
//   , token: ""
//   , protocol: "https"
//   , toString: [Function]
//   , source: "github.com"
//   , name: "node-git-url-parse"
//   , owner: "IonicaBizau"
// }

console.log(GitUrlParse("https://github.com/IonicaBizau/git-url-parse/blob/master/test/index.js"));
// { protocols: [ 'https' ],
//   protocol: 'https',
//   port: null,
//   resource: 'github.com',
//   user: '',
//   pathname: '/IonicaBizau/git-url-parse/blob/master/test/index.js',
//   hash: '',
//   search: '',
//   href: 'https://github.com/IonicaBizau/git-url-parse/blob/master/test/index.js',
//   token: '',
//   toString: [Function],
//   source: 'github.com',
//   name: 'git-url-parse',
//   owner: 'IonicaBizau',
//   organization: '',
//   ref: 'master',
//   filepathtype: 'blob',
//   filepath: 'test/index.js',
//   full_name: 'IonicaBizau/git-url-parse' }

console.log(GitUrlParse("https://github.com/IonicaBizau/node-git-url-parse.git").toString("ssh"));
// => "[email protected]:IonicaBizau/node-git-url-parse.git"

console.log(GitUrlParse("[email protected]:IonicaBizau/node-git-url-parse.git").toString("https"));
// => "https://github.com/IonicaBizau/node-git-url-parse.git"

❓ Get Help

There are few ways to get help:

  1. Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
  2. For bug reports and feature requests, open issues. πŸ›
  3. For direct and quick help, you can use Codementor. πŸš€

πŸ“ Documentation

gitUrlParse(url)

Parses a Git url.

Params

  • String url: The Git url to parse.

Return

  • GitUrl The GitUrl object containing:
  • protocols (Array): An array with the url protocols (usually it has one element).
  • port (null|Number): The domain port.
  • resource (String): The url domain (including subdomains).
  • user (String): The authentication user (usually for ssh urls).
  • pathname (String): The url pathname.
  • hash (String): The url hash.
  • search (String): The url querystring value.
  • href (String): The input url.
  • protocol (String): The git url protocol.
  • token (String): The oauth token (could appear in the https urls).
  • source (String): The Git provider (e.g. "github.com").
  • owner (String): The repository owner.
  • name (String): The repository name.
  • ref (String): The repository ref (e.g., "master" or "dev").
  • filepath (String): A filepath relative to the repository root.
  • filepathtype (String): The type of filepath in the url ("blob" or "tree").
  • full_name (String): The owner and name values in the owner/name format.
  • toString (Function): A function to stringify the parsed url into another url type.
  • organization (String): The organization the owner belongs to. This is CloudForge specific.
  • git_suffix (Boolean): Whether to add the .git suffix or not.

stringify(obj, type)

Stringifies a GitUrl object.

Params

  • GitUrl obj: The parsed Git url object.
  • String type: The type of the stringified url (default obj.protocol).

Return

  • String The stringified url.

πŸ˜‹ How to contribute

Have an idea? Found a bug? See how to contribute.

πŸ’– Support my projects

I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).

However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:

  • Starring and sharing the projects you like πŸš€

  • Buy me a bookβ€”I love books! I will remember you after years if you buy me one. 😁 πŸ“–

  • PayPalβ€”You can make one-time donations via PayPal. I'll probably buy a coffee tea. 🍡

  • Support me on Patreonβ€”Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).

  • Bitcoinβ€”You can send me bitcoins at this address (or scanning the code below): 1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6

Thanks! ❀️

πŸ’« Where is this library used?

If you are using this library in one of your projects, add it in this list. ✨

  • lerna
  • release-it
  • @backstage/backend-common
  • documentation
  • apollo
  • @backstage/integration
  • @storybook/storybook-deployer
  • @atomist/automation-client
  • @plone/scripts
  • workspace-tools
  • @backstage/plugin-catalog-backend
  • @pvm/core
  • nextra-theme-docs
  • @kadira/storybook-deployer
  • gatsby-source-git
  • @nuxt/telemetry
  • umi-build-dev
  • @era-ci/utils
  • strapi-generate-new
  • git-source
  • @atomist/automation-client-ext-raven
  • renovate
  • semantic-release-gitmoji
  • @qiwi/semantic-release-gh-pages-plugin
  • @backstage/plugin-scaffolder
  • apify-shared
  • @atomist/sdm-pack-analysis
  • @git-stack/server-core
  • @backstage/cli
  • @backstage/plugin-techdocs-node
  • @dtwo/telemetry
  • @lerna/create
  • remax-stats
  • @s-ui/mono
  • common-boilerplate
  • @strapi/pack-up
  • @umijs/block-sdk
  • @backstage/plugin-techdocs
  • @akemona-org/strapi-generate-new
  • @stackbit/cms-git
  • package-json-from-git
  • pupils-generate-new
  • @toanz/strapi-generate-new
  • @x-team/strapi-generate-new
  • @servable/manifest
  • @backstage/plugin-catalog-import
  • @s-ui/studio
  • @appworks/project-utils
  • @jswork/next-git-url
  • @backstage/plugin-github-actions
  • @wetrial/block-sdk
  • datoit-generate-new
  • @micro-app/shared-utils
  • @appirio/appirio
  • @radjs/block-sdk
  • @stackbit/dev-common
  • @useoptic/optic
  • @tasenor/common-node
  • @oumi/block-sdk
  • @sanity/pkg-utils
  • @qoopido/lerna.version
  • @log4brains/core
  • @yarnpkg/plugin-git
  • @xdn/cli
  • @madm4ttus3r/l4bcore
  • @atomist/skill
  • @zeplin/cli
  • @lerna/github-client
  • @koumoul/gh-pages-multi
  • @brisk-docs/gatsby-generator
  • clipped
  • codesandbox-theme-docs
  • git-issues
  • gitbook-start-plugin-iaas-ull-es-noejaco2017
  • fotingo
  • hzero-block-sdk
  • miguelcostero-ng2-toasty
  • @microservices/cli
  • omg
  • @guardian/cdk
  • @atomist/cli
  • @vamsikc/plugin-catalog
  • @lerna-lite/version
  • @praella/localisationist
  • @spryker-lerna/github-client
  • copy-github-directory
  • docula-ui
  • lambda-service
  • octokit-downloader
  • sync-repos
  • stylelint-formatter-utils
  • @mongchhi/plugin-blocks
  • @enkeledi/react-native-week-month-date-picker
  • @tmplr/node
  • @kevinbds/techdocs-common
  • autorelease-setup
  • scaffolder-core
  • @facadecompany/ignition-ui
  • @geut/git-url-parse
  • @git-stack/hemera-plugin
  • testarmada-midway
  • react-native-shared-gesture
  • @lerna/legacy-package-management
  • @jaredpalmer/workspace-tools
  • @focusworkstemp/project-utils
  • @unibtc/release-it
  • @backstage/plugin-techdocs-module-addons-contrib
  • changelog.md
  • react-native-nice-learning
  • wiby
  • @erquhart/lerna-github-client
  • sherry-utils
  • @oumi/cli-ui
  • @monokle/synchronizer
  • @vrabbi/plugin-scaffolder-backend
  • @backstage/plugin-scaffolder-backend-module-confluence-to-markdown
  • @0x-lerna-fork/github-client
  • documentation-custom-markdown
  • @atomist/uhura
  • @vrabbi/plugin-scaffolder
  • @antv/gatsby-theme-antv
  • @pmworks/project-utils
  • @pubbo/github-client
  • @sanv/apify-shared
  • @scafflater/scafflater
  • gcpayz-block-sdk
  • @feizheng/next-git-url
  • @iceworks/project-utils
  • @hygiene/plugin-github-url
  • servable-manifest
  • tegit
  • @backstage/plugin-catalog-backend-module-github
  • auto-changelog-vsts
  • @belt/repo
  • @wolfy1339/gatsby-source-git
  • @axetroy/gpm
  • belt-repo
  • @brisk-docs/website
  • create-apex-js-app
  • cz-conventional-changelog-befe
  • cover-builder
  • @buschtoens/documentation
  • development-efficiency
  • debone
  • @deskbtm/workspace-tools
  • git-origin-check
  • git-yoink
  • git-service-node
  • gitbook-start-iaas-bbdd-alex-moi
  • gitbook-start-iaas-ull-es-merquililycony
  • gitc
  • @ckatzorke/renovate
  • @_nomtek/react-native-shimmer-animation
  • mdnext-loader
  • lime-cli
  • kef-core
  • khaled-salem-custom-components
  • @dandean/storybook-deployer
  • jsnix
  • l-other-data
  • laborious
  • konitor
  • konfig-release-it
  • native-kakao-login
  • @dfatwork-pkgs/backstage-cli
  • open-pull-request
  • npm_one_1_2_3
  • gtni
  • fster
  • griffin-ui-library
  • gatsby-theme-zh
  • gatsby-source-git-remotes
  • gaurav-react-native-loop
  • gatsby-source-npmjs
  • gitlab-ci-variables-cli
  • harry-reporter
  • @cliz/gpm
  • framework_test_library_sixdee
  • fluent.adflow.reactnativesdk-alpha
  • ewizard-cli
  • prep-barv11
  • react-native-azure-communication-services
  • react-native-android-video-player-view
  • react-native-animate-text
  • react-native-arunmeena1987
  • react-native-basic-screen
  • react-native-build-vesion-getter
  • react-native-biometric-authenticate
  • react-native-check-component
  • react-native-bleccs-components
  • react-native-ghn-ekyc
  • react-native-kakao-maps
  • react-native-klc
  • react-native-manh-test
  • react-native-library-testing-422522
  • release-it-http
  • react-native-test-comlibrary
  • react-native-uvc-camera-android
  • react-native-withframework-check
  • react-native-ytximkit
  • react-native-multiplier-component
  • react-native-multiplier-demo
  • react-native-multiplier2
  • react-native-multiselector
  • react-native-payu-payment-testing
  • react-native-my-first-try-arun-ramya
  • react-native-progress-arrow
  • react-native-reanimated-sortable-list
  • react-native-rom-components
  • react-native-contact-list
  • react-native-create-video-thumbnail
  • react-native-components-design
  • react-native-module-for-testing
  • spk
  • redhatinsights-plugin-scaffolder-backend
  • simple-github-release
  • tanyao
  • @emedvedev/renovate
  • @hugomrdias/documentation
  • @hemith/react-native-tnk
  • snipx
  • @janus-idp/backstage-plugin-topology
  • @mmomtchev/documentation
  • @salla.sa/cli
  • @jswork/topics2keywords
  • @amiruldev/wajs
  • @safely-project/safely-ts
  • @rianfowler/backstage-backend-common
  • @status-im/react-native-transparent-video
  • @pvdlg/semantic-release
  • @rdfrontier/plugin-mobile
  • @veecode-platform/plugin-github-actions
  • @lehuyaa/my-assets
  • @lerna-test-v1/markdown
  • @pageshare/cli
  • @parallelnft/web3modal
  • @visulima/nextra-theme-docs
  • @xyz/create-package
  • react-native-cplus
  • react-native-input-library
  • react-native-klarify-ios
  • react-native-login-demo-test
  • react-native-jawwy_sample
  • react-native-arunjeyam1987
  • react-native-basic-app
  • react-native-bubble-chart
  • react-native-awesome-module-two
  • react-native-dhp-printer
  • react-native-flyy
  • react-native-innity-remaster
  • template-typescript-node-package
  • repom
  • storybook-deployer
  • rdmobile
  • react-native-rabbitmq-all
  • react-native-sandycomponent
  • react-native-savczuk-feature-library
  • react-native-ticker-tape
  • rn-check-btn
  • rn_unique_device_id
  • pr-log
  • semantic-release-squash3
  • publish-version
  • pyreswap-sdk
  • renovate-csm
  • test-library-123
  • @blackglory/git-list
  • checkbox-component
  • complan
  • configorama
  • @brainfried/github-books
  • def-core
  • bitbucket-pullr
  • tldw
  • nextra-theme-docs-mdxcomponents
  • manage-dependency
  • wsj.gatsby-source-git
  • winx-form-winx
  • zeo-collect
  • @felipesimmi/react-native-datalogic-module
  • @geut/chan-parser
  • @hawkingnetwork/react-native-tab-view
  • @infinitecsolutions/storybook-deployer
  • pbc
  • @voodeng/uppacks
  • toxics-rpc
  • @esops/publish-github-pages
  • @evanpurkhiser/tooling-personal
  • @oiti/rn-liveness2d
  • semantic-release-github-milestones
  • @taingo97/react-native-sunmi-printer
  • @taingo97/react-native-telpo-printer
  • @theowenyoung/gatsby-source-git
  • @speakeasy-sdks/nextra-theme-docs
  • @shopgate/pwa-releaser
  • @rocali/apollo
  • @stackbit/cli
  • @stepsec/release
  • @edgio/cli
  • @axetroy/git-clone
  • aral-vps-test
  • auto-clone
  • awesome-module-kd
  • @wekanteam/documentation
  • candlelabssdk
  • canarist
  • detect-node-support
  • @aysea/react-native-ui-library
  • @azalpacir/react-native-dhp-printer
  • @campus-online/gatsby-source-git
  • @x-team/create-strapi-starter
  • cirodown
  • create-pupils-starter
  • branch-release
  • fixed_form_builder
  • @1nd/documentation
  • @carrotwu/wcli
  • gatsby-theme-art-graph
  • gatsby-theme-cone-oc
  • gatsby-theme-iot
  • gd-cli
  • generate-preview
  • generator-bootstrap-boilerplate-template
  • generator-frida
  • gitline
  • semantic-release-telegram
  • @echolayer/plugin-backstage
  • @geeky-apo/react-native-advanced-clipboard
  • yangtao-js
  • yarn-upgrade-on-ci
  • wp-continuous-deployment
  • @ali5049/react-native-buttons
  • @gogogosir/build-cli
  • @git-stack/module-server
  • @dvcorg/cml
  • @domestika/mono
  • react-native-sp-test-common
  • react-native-ui-components-library
  • react-native-xprinter-thermal-ble
  • reat-native-multiplierkpr
  • sn-flutter-boot
  • react-native-get-countries
  • react-native-dsphoto-module
  • react-native-lib-test-rn-1
  • react-native-native-audio-engine
  • react-native-onramp
  • react-native-nghia-sharering
  • react-native-recent-framework-update

πŸ“œ License

MIT © Ionică Bizău

git-url-parse's People

Contributors

3fd avatar cbargren avatar choldgraf avatar gabrielcsapo avatar ggdaltoso avatar goober avatar gyandeeps avatar ionicabizau avatar lfcyja avatar lykims avatar mapaiva avatar msivasubramaniaan avatar n2ygk avatar privatenumber avatar pvdlg avatar redonkulus avatar romanhotsiy avatar sinchang avatar vedranjukic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

git-url-parse's Issues

[Bitbucket Server] Organization and owner are different in case of https and ssh

Hi,

I get different results with Bitbucket Server URL in case of https and ssh.

HTTPS:

var gitUrlParse = require("git-url-parse")
const parsed = gitUrlParse("https://[email protected]:8443/bitbucket/scm/lpbran/testrepo1.git");
Object
organization: "bitbucket/scm/lpbran"
owner: "bitbucket/scm/lpbran"

SSH:

var gitUrlParse = require("git-url-parse")
const parsed = gitUrlParse("ssh://[email protected]:7999/lpbran/testrepo1.git");
Object
organization: "lpbran"
owner: "lpbran"

Thank you and kind regards,
pII

stringify silently ignores token

Stringify methond ignores token field.

const GitUrlParse = require("git-url-parse");
const url = '[email protected]:user/repo.git';
const obj = GitUrlParse(url);
obj.token = 'token';
GitUrlParse.stringify(obj, 'https');
// we get "https://github.com/user/repo"
// bug e.g. for github expected is "https://[email protected]/user/repo"

From #10 I know that token format differs across providers.
So the possible way to fix this is to have switch based on source field. And if source is neither github.com nor bitbucket.com and token field is present then throw an error (currently it just silently ignores token which leads to bugs).

Maybe you can come up with some better way to fix this. If not I will send a PR

can't parse GH Enterprise SSH URLs with different username

Description

GitHub Enterprise repositories doesn't use the git username in SSH urls, and can look like this:

[email protected]:squareup/repo-name.git

When parsed, it seems to include the username in the owner, organization, full_name properties:

{
    protocols: [ 'file' ],
    protocol: 'file',
    port: '',
    resource: '',
    user: '',
    password: '',
    pathname: '',
    hash: '',
    search: '',
    href: '[email protected]:squareup/repo-name.git',
    query: {},
    token: '',
    toString: [Function (anonymous)],
    source: '',
    git_suffix: false,
    name: 'repo-name',
    owner: '[email protected]:squareup',
    commit: undefined,
    ref: '',
    filepathtype: '',
    filepath: '',
    organization: '[email protected]:squareup',
    full_name: '[email protected]:squareup/repo-name'
}

Context

This is affecting lerna's ability to publish to GitHub Enterprise repositories.

Support non-GitHub providers better

Great little utility you have here! It'd be nice if it handled non-GitHub providers a little better. For instance, with Bitbucket, HTTPS URL's take the form of https://<owner>@bitbucket.org/<owner>/<name>, which results in a incorrect value for source of <owner>@bitbucket.org.

The latest update does not work anymore with internal machine names

The latest update fails when trying to parse URLs like: http://machine:8080/tfs/Collection/Project.Name/_git/repository

The error is caused by the parse-url library:

TypeError: Cannot read property 'domain' of null at gitUrlParse (D:\Dev\i4\i4-common\node_modules\git-url-parse\lib\index.js:51:37)

Slash in revision name

if there's a / in revision name (either for tag or branch) then url is parsed in a wrong manner and cuts the revision name from the existing /. so for e.g if branch name is feature/foo then git-url-parse would fetch the revision name as feature leaving /foo out.

GitHub SSH URLs interpret numerical usernames as ports

Not sure what to do about this one...

A typical github.com SSH url is something like [email protected]:user/repo.git. If the user is a number, then it gets parsed as a port. The problem is that GitHub has users whose names are just numbers.

Parsing that number as a port makes sense in every context unless we know that it's a GitHub (or GitHub Enterprise) URL. GitHub doesn't allow SSH over any port except 22, and GitHub Enterprise doesn't either (it's not configurable by the admin). They probably do this specifically to avoid this issue; if the port can't be anything but 22, then the URL format is no longer ambiguous; that thing after a colon is always a user name.

Not sure what to do about this. For github.com you could probably add a bunch of logic to git-url-parse after you get it back from git-up and see that the domain is github.com... it would involve doing really heavy surgery on the object to fix it up, but it's technically possible. That doesn't solve the problem for Enterprise URLs though, and I don't see how that's solvable without being able to pass options to git-url-parse.

Wrong parsing for git URL with path containing more than 2 elements

With 2 elements in the path:

GitUrlParse("[email protected]:a/b.git");
{ protocols: [],
  protocol: 'ssh',
  port: null,
  resource: 'github.com',
  user: 'git',
  pathname: '/a/b.git',
  hash: '',
  search: '',
  href: '[email protected]:a/b.git',
  token: '',
  toString: [Function],
  source: 'github.com',
  name: 'b',
  owner: 'a',
  organization: 'git',
  full_name: 'a/b' }

Everything seems correct except the organization that is set to git.

With more than 2 elements in the path:

GitUrlParse("[email protected]:a/b/c/d.git");
{ protocols: [],
  protocol: 'ssh',
  port: null,
  resource: 'github.com',
  user: 'git',
  pathname: '/a/b/c/d.git',
  hash: '',
  search: '',
  href: '[email protected]:a/b/c/d.git',
  token: '',
  toString: [Function],
  source: 'github.com',
  name: 'a/b/c/d',
  owner: 'git',
  organization: 'git',
  full_name: 'git/a/b/c/d' }

The name, owner, organization and full_name are wrong.

This type of URL are valid for GitLab repositories in a sub-group: https://docs.gitlab.com/ee/user/group/subgroups/index.html

Owner is parsed incorrectly when GitHub user name is a hex number, e.g., '0xABC'

Repro:

const GitUrlParse = require("git-url-parse");

const a = GitUrlParse("[email protected]:0xABCDEF/myreponame.git");
const b = GitUrlParse("[email protected]:1xABCDEF/myreponame.git");
const c = GitUrlParse("[email protected]:zxABCDEF/myreponame.git");

console.log(a.owner, a.full_name); // BUGGY => git git/myreponame
console.log(b.owner, b.full_name); // OK => 1xABCDEF 1xABCDEF/myreponame
console.log(c.owner, c.full_name); // OK => zxABCDEF zxABCDEF/myreponame

I have a git url to parse where the owner's GitHub user name is a hexadecimal number. :-)

Stringify - repo urls containing more than two sub-folders are incorrectly re-formed

Seems to be an issue with stringify removing sub-folders from a parsed repo url (v8.0.1):

const url = GitUrlParse("https://www.example.com/tripleaxis/node/myproject.git").toString('https');
console.log(url);
// expected: 'https://www.example.com/tripleaxis/node/myproject.git'
// output: 'https://www.example.com/tripleaxis/node'

It seems the full_name property is being used in the reconstruction instead of pathname.

Possible to grab reference information as well?

Hey there! I'm looking into using this for the Binder project running at mybinder.org, we need to parse URLs for git repositories and determine if they're a github repo / gist / gitlab repo / etc. It seems that this gets quite close! However, we need to be able to determine a reference as well as the repo information (e.g. a branch name). Am I right in thinking this doesn't currently work w/ git-url-parse?

E.g., this works:

 GitUrlParse("https://gitlab.com/fdroid/fdroidclient")
OUT:
{ protocols: [ 'https' ],
  protocol: 'https',
  port: null,
  resource: 'gitlab.com',
  user: '',
  pathname: '/fdroid/fdroidclient',
  hash: '',
  search: '',
  href: 'https://gitlab.com/fdroid/fdroidclient',
  token: '',
  toString: [Function],
  source: 'gitlab.com',
  name: 'fdroidclient',
  owner: 'fdroid',
  organization: '',
  full_name: 'fdroid/fdroidclient' }

whereas this seems to trip up a bit:

GitUrlParse("https://gitlab.com/fdroid/fdroidclient/tree/stable-v0.102")

OUT:
{ protocols: [ 'https' ],
  protocol: 'https',
  port: null,
  resource: 'gitlab.com',
  user: '',
  pathname: '/fdroid/fdroidclient/tree/stable-v0.102',
  hash: '',
  search: '',
  href: 'https://gitlab.com/fdroid/fdroidclient/tree/stable-v0.102',
  token: '',
  toString: [Function],
  source: 'gitlab.com',
  name: 'fdroid/fdroidclient/tree/stable-v0.102',
  owner: '',
  organization: '',
  full_name: 'fdroid/fdroidclient/tree/stable-v0.102' }

Have you given any thoughts to this usecase?

branches with `/` fails

It's common to see branch names that follows the git flow, eg something like features/LGT-343-crud

for the parser to correctly parsing the ref and filepath it would need information of what branches there exists for a given repo...

take this for example: https://github.com/node-fetch/node-fetch/blob/dependabot/npm_and_yarn/tsd-0.20.0/.gitignore

the ref should be dependabot/npm_and_yarn/tsd-0.20.0 and the filepath should be .gitignore

it's possible to get all the branches from githubs api using: https://api.github.com/repos/node-fetch/node-fetch/branches

Consider removing `parse-domain` dependency?

A dependency to parse-domain was added in #56.

parse-domain download and copy locally some files on a postinstall script.
As git-url-parse is a fairly small and dependency free module and it was possible to use it anywhere really easily like in a browser or an environment without open access to inter (only access to a npm registry replica).

With the parse-domain dependency it's not possible anymore. In addition the download mechanism create issues for many users: peerigon/parse-domain#35 for a month and a half now.

Would you consider reverting the changes added in #56 to remove the dependency to parse-domain and possibly later find an alternate solution to fix #56?

Thanks!

Bitbucket path with /src/ instead of /tree/ or /blob/

Hi, when running gitUrlParse('https://bitbucket.org/org-name/project-name/src/master/ops/assets/'); I would expected to receive this

{
  "protocols": [
    "https"
  ],
  "protocol": "https",
  "port": null,
  "resource": "bitbucket.org",
  "user": "",
  "pathname": "/org-name/project-name/src/master/ops/assets",
  "hash": "",
  "search": "",
  "href": "https://bitbucket.org/org-name/project-name/src/master/ops/assets",
  "token": "",
  "source": "bitbucket.org",
  "git_suffix": false,
  "name": "project-name",
  "owner": "org-name",
  "commit": "master",
  "ref": "master",
  "filepathtype": "src",
  "filepath": "ops/assets",
  "organization": "org-name",
  "full_name": "org-name/project-name"
}

but instead I'm getting

{
  "protocols": [
    "https"
  ],
  "protocol": "https",
  "port": null,
  "resource": "bitbucket.org",
  "user": "",
  "pathname": "/org-name/project-name/src/master/ops/assets",
  "hash": "",
  "search": "",
  "href": "https://bitbucket.org/org-name/project-name/src/master/ops/assets",
  "query": {},
  "token": "",
  "source": "bitbucket.org",
  "git_suffix": false,
  "name": "assets",
  "owner": "org-name/project-name/src/master/ops",
  "ref": "",
  "filepathtype": "",
  "filepath": "",
  "organization": "org-name/project-name/src/master/ops",
  "full_name": "org-name/project-name/src/master/ops/assets"
}

Just as a matter of test, if I changes /src/ with /tree/ it works fine and gives me:

{
  "protocols": [
    "https"
  ],
  "protocol": "https",
  "port": null,
  "resource": "bitbucket.org",
  "user": "",
  "pathname": "/org-name/project-name/tree/master/ops/assets",
  "hash": "",
  "search": "",
  "href": "https://bitbucket.org/org-name/project-name/tree/master/ops/assets",
  "query": {},
  "token": "",
  "source": "bitbucket.org",
  "git_suffix": false,
  "name": "project-name",
  "owner": "org-name",
  "commit": "master",
  "ref": "master",
  "filepathtype": "tree",
  "filepath": "ops/assets",
  "organization": "org-name",
  "full_name": "org-name/project-name"
}

Incorrect result when parsing relative path

Version: 9.0.0

Reproduction:

const GitUrlParse = require('git-url-parse');
console.log(GitUrlParse('https://github.com/IonicaBizau/git-url-parse').full_name); 'IonicaBizau/git-url-parse'
console.log(GitUrlParse('IonicaBizau/git-url-parse').full_name); // 'onicaBizau/git-url-parse'

Expected result: in the second case it either recognizes it as a relative path and parses it correctly, or indicate that it could not parse. Shouldn't return this wrong and meaningless result.

GitLab URLs with dashes are parsed incorrectly

Context

Some GitLab Web Project URLs now sometimes have dashes in their path. This is dependent on the version of GitLab and when it is the case GitLab will redirect for some.

Expected behaviour

The library correctly parses GitLab URLs with /-/ scope.

Actual behaviour

name, full_name, organization, owner are incorrect

~ ❯ node                                                                                                                                                                                                             Welcome to Node.js v12.18.2.
Type ".help" for more information.
> parse = require('./lib/index.js')
[Function: gitUrlParse] { stringify: [Function] }
> parse("https://gitlab.com/a/b/c/d/-/blob/master/test/index.js")
{
  protocols: [ 'https' ],
  protocol: 'https',
  port: null,
  resource: 'gitlab.com',
  user: '',
  pathname: '/a/b/c/d/-/blob/master/test/index.js',
  hash: '',
  search: '',
  href: 'https://gitlab.com/a/b/c/d/-/blob/master/test/index.js',
  query: [Object: null prototype] {},
  token: '',
  toString: [Function],
  source: 'gitlab.com',
  git_suffix: false,
  name: '-',
  owner: 'a/b/c/d',
  commit: 'master',
  ref: 'master',
  filepathtype: 'blob',
  filepath: 'test/index.js',
  organization: 'a/b/c/d',
  full_name: 'a/b/c/d/-'
}

URIs such as git://github.com:user/repo no longer parsed correctly

Since the update to version 12.0.0, parsing a URI like git://github.com:user/repo returns the following incorrect output:

{
  protocols: [ 'file' ],  
  protocol: 'file',  
  port: '',
  resource: '',
  user: '',
  password: '',
  pathname: '',
  hash: '',
  search: '',
  href: 'git://github.com:user/repo',
  query: {},
  token: '',
  toString: [Function (anonymous)],
  source: '',
  git_suffix: false,
  name: 'repo',
  owner: 'git://github.com:user',
  commit: undefined,
  ref: '',
  filepathtype: '',
  filepath: '',
  organization: 'git://github.com:user',
  full_name: 'git://github.com:user/repo'
}

This breaks functionality in projects such as release-it.
Is this intended behavior?

Thank you

GitLab URL parsing with `git@` URLs

parse(`[email protected]/really-long-group/with-really-long-sub-group/and-a-really-long-project-name.git`)

Returns the following results:

{ protocols: [],
  protocol: 'file',
  port: null,
  resource: '',
  user: '',
  pathname: '[email protected]/really-long-group/with-really-long-sub-group/and-a-really-long-project-name.git',
  hash: '',
  search: '',
  href: '[email protected]/really-long-group/with-really-long-sub-group/and-a-really-long-project-name.git',
  query: {},
  token: '',
  toString: [Function],
  source: '',
  git_suffix: true,
  name: 'and-a-really-long-project-name',
  owner: '[email protected]/really-long-group/with-really-long-sub-group',
  commit: undefined,
  ref: '',
  filepathtype: '',
  filepath: '',
  organization: '[email protected]/really-long-group/with-really-long-sub-group',
  full_name: '[email protected]/really-long-group/with-really-long-sub-group/and-a-really-long-project-name' }

I was hoping it would return the following properties:

{
  resource: 'gitlab.com',
  name: `and-a-really-long-project-name`,
  owner: `really-long-group/with-really-long-sub-group`
}

It pulled out the name as desired, but not the resource or owner.

custom ports should be removed before converting to http

If a protocol is listening on a port, we can safely assume any other protocol will not be.

I fixed it in the 3rd line of stringify with:

var port = (obj.port && type === obj.protocol) ? ":" + obj.port : '';

Useful when converting to http(s)

normalize-url v3 is vulnerable

Following the issues IonicaBizau/parse-url#19 and IonicaBizau/git-up#24, git-url-parse should have an updated version of git-up to fix the vulnerability.

Two versions to verify:

Details about the security issue: https://www.npmjs.com/advisories/1755

Support filepath for Azure DevOps

Hello,

I tried parsing an Azure DevOps url and found out that the filepath is not set, even though it is present as a query parameter.

GitUrlParse('https://dev.azure.com/organization/project/_git/repo?path=%2Ffolder%2Ffile.ext') gives the following:

{
  protocols: [ 'https' ],
  protocol: 'https',
  port: null,
  resource: 'dev.azure.com',
  user: '',
  pathname: '/organization/project/_git/repo',
  hash: '',
  search: 'path=%2Ffolder%2Ffile.ext',
  href: 'https://dev.azure.com/organization/project/_git/repo?path=%2Ffolder%2Ffile.ext',
  query: [Object: null prototype] { path: '/folder/file.ext' },
  token: '',
  toString: [Function],
  source: 'azure.com',
  git_suffix: false,
  name: 'repo',
  owner: 'project',
  organization: 'organization',
  full_name: 'organization/project/_git/repo'
}

I would like the filepath property to be set to folder/file.ext in this case.

Incorrect pathname on Windows

OS: Windows 10 Home, using "bash" (Windows Subsystem for Linux).

call:
gitUrlParse('[email protected]:IonicaBizau/node-git-url-parse.git')
pathName returned:
pathname: '/:IonicaBizau/node-git-url-parse.git'

it puts ":" after first / in pathname

EDIT:
it seems not to happen running your "example" project.
I'll close this issue for now.

EDIT 2: I had v10 of the library. Resolved with 11.1.2

Parsing of git url fails if it has 'commits' in it

For example, https://github.com/IonicaBizau/git-url-parse/commits/master is a valid URL as per GitHub, but git-url-parse fails to parse and returns:

{
  protocols: [ 'https' ],
  protocol: 'https',
  port: null,
  resource: 'github.com',
  user: '',
  pathname: '/IonicaBizau/git-url-parse/commits/master',
  hash: '',
  search: '',
  href: 'https://github.com/IonicaBizau/git-url-parse/commits/master',
  query: [Object: null prototype] {},
  token: '',
  toString: [Function],
  source: 'github.com',
  git_suffix: false,
  name: 'master',
  owner: 'IonicaBizau/git-url-parse/commits',
  commit: undefined,
  ref: '',
  filepathtype: '',
  filepath: '',
  organization: 'IonicaBizau/git-url-parse/commits',
  full_name: 'IonicaBizau/git-url-parse/commits/master'
}

see owner, commit, ref etc...

String without `.git` postfix support.

This will really help if we wanna access the repo without git but its website, some tools may not work fine with the http redirect, and also, there may be a repo without .git postfix, I would like to have an option to disable that, thanks.

Incorrect parsing of SSH remote URLs when no owner/organisation in the URL

Hi, there appears to be a bug when parsing remote URLs that use SSH and have no owner/organisation.

> remote = '[email protected]:repo.git'
'[email protected]:repo.git'
> parsed = GitUrlParse(remote)
{ protocols: [],
  protocol: 'ssh',
  port: null,
  resource: 'gitlab.com',
  user: 'git',
  pathname: '/repo.git',
  hash: '',
  search: '',
  href: '[email protected]:repo.git',
  token: '',
  toString: [Function],
  source: 'gitlab.com',
  name: 'repo',
  owner: 'git',
  git_suffix: false,
  ref: '',
  filepathtype: '',
  filepath: '',
  organization: 'git',
  full_name: 'git/repo' }
> parsed.toString('https')
'https://gitlab.com/git/repo.git'

The expected behaviour is

> parsed.toString('https')
'https://gitlab.com/repo.git'

I'm running the latest version (8.2.0).

ssh to http doesnt have .git at the end

OS: Windows 7
Node: 8.0.1
Version: 6.2.2
CLI: git bash

Case 1: ssh -> https

console.log(GitUrlParse("[email protected]:IonicaBizau/node-git-url-parse.git").toString("https"));
// => "https://github.com/IonicaBizau/node-git-url-parse"

Case 2: https -> https

console.log(GitUrlParse("https://github.com/IonicaBizau/node-git-url-parse.git").toString("https"));
// => "https://github.com/IonicaBizau/node-git-url-parse"

I am using the code from the example from README.

I can work on the fix if you agree that this is a bug.

Example from README fails (ssh url parsing)

Hi, @IonicaBizau

Thanks for the great library! I noticed that an example from README does not work as expected in 10.1.0 version of the library:

> const GitUrlParse = require("git-url-parse");
> GitUrlParse("[email protected]:IonicaBizau/node-git-url-parse.git").toString("https")

'https://[email protected]/:IonicaBizau/node-git-url-parse.git'

while in README the result is:

'https://github.com/IonicaBizau/node-git-url-parse.git'

In case I'm not aware of internal API change, how is it possible to conver an ssh url to https one?

URL should be trimmed before parsing

const gitUrlParse = require("..");
gitUrlParse(' http://github.com/IonicaBizau/git-url-parse ');
/*
{ protocols: [ ' http' ],
  protocol: ' http',
  port: null,
  resource: 'github.com',
  user: '',
  pathname: '/IonicaBizau/git-url-parse ',
  hash: '',
  search: '',
  href: ' http://github.com/IonicaBizau/git-url-parse ',
  token: '',
  toString: [Function],
  source: 'github.com',
  name: 'git-url-parse ',
  owner: 'IonicaBizau',
  git_suffix: false,
  ref: '',
  filepathtype: '',
  filepath: '',
  organization: 'IonicaBizau',
  full_name: 'IonicaBizau/git-url-parse ' }
*/

Parsing a URL with extra spaces result in wrong properties for protocols, protocol, pathname, name , href and full_name.

I'd like to propose a PR to trim the URL passed to the parser. However I'm not sure if you prefer to do that in git-url-parse, git-up, parse-url or parse-path.
I would imagine parse-path is the right place? Unless spaces are allowed at the beginning and end of path? I know they are not significant in URLs but not sure about FileSystem paths.

[Bitbucket Server] Ssh protocol in the result with https clone URI

Hi,

I have a Bitbucket Server HTTPS clone URL.
But the Protocol is SSH in the result.
In this case user is the username from username:password@ for basic auth.

var gitUrlParse = require("git-url-parse")
const parsed = gitUrlParse("https://[email protected]:8443/bitbucket/scm/lpbran/testrepo1.git");
Object
commit: undefined
filepath: ""
filepathtype: ""
full_name: "bitbucket/scm/lpbran/testrepo1"
git_suffix: true
hash: ""
href: "https://[email protected]:8443/bitbucket/scm/lpbran/testrepo1.git"
name: "testrepo1"
organization: "bitbucket/scm/lpbran"
owner: "bitbucket/scm/lpbran"
pathname: "/bitbucket/scm/lpbran/testrepo1.git"
port: 8443
protocol: "ssh"
protocols: ["https"]
query: Object {}
ref: ""
resource: "servername.org"
search: ""
source: "servername.org"
toString: function()
token: ""
user: "user"

Thank you and kind regards,
pII

Github does not add x-oauth-basic for https with token

We need to specify x-oauth-basic when we use a GitHub Personal Access Token.

The format for an OAuth url in GitHub is https://<token>:[email protected]/<owner>/<name>.git.

I think we should add a case for github.com to return <token>:x-oauth-basic@.

git-url-parse/lib/index.js

Lines 272 to 279 in 71c7298

function buildToken(obj) {
switch (obj.source) {
case "bitbucket.org":
return `x-token-auth:${obj.token}@`;
default:
return `${obj.token}@`
}
}

Related to #10

Parsing fundamentally invalid URLs

I ran some valid and invalid URLs from Github's URL Normalization tests (link here) and for cases that are fully invalid (such as scheme://invalid....:[ or ://acme.co) i am getting valid parsing.

values.scm_url is the string value we give GitUrlParse() and parsed is the resulting output for those cases.
I'm logging this issues on Google Chrome version 98.0.4758.80 and node v12.7.0

Examples:
Return for scheme://invalid....:[

filepathtype: ""
full_name: "["
git_suffix: false
hash: ""
href: "scheme://invalid....:["
name: "["
organization: ""
owner: ""
pathname: "/["
port: null
protocol: "ssh"
protocols: ['scheme']
query: {}
ref: ""
resource: "invalid...."
search: ""
source: "..."
toString: Ζ’ (type)
token: ""
user: ""

Return for ://acme.co

filepath: ""
filepathtype: ""
full_name: "://acme.co"
git_suffix: false
hash: ""
href: "://acme.co"
name: "acme.co"
organization: ":/"
owner: ":/"
pathname: "://acme.co"
port: null
protocol: "file"
protocols: []
query: {}
ref: ""
resource: ""
search: ""
source: ""
toString: Ζ’ (type)
token: ""
user: ""

Option to omit the `.git` suffix?

If we want to parse the url and use it as a hyperlink, e.g <a href="">, current way of parsing and stringify the url still leaves .git as suffix

GitUrlParse("[email protected]:IonicaBizau/node-git-url-parse.git").toString("https")
// => "https://github.com/IonicaBizau/node-git-url-parse.git"
// but it would be cleaner if it's just "https://github.com/IonicaBizau/node-git-url-parse"

Can we add an option to omit the .git when using .toString()? And if not, what would be the reason for not implementing it? Happy to submit a PR for it

VSTS url

While using npm package semantic-release they will check the validity by git push --dry-run <repositoryUrl>. And they will use gitUrlParse to get the repositoryURL.
However, the repositoryURL your current version return is like https://[secure]@companyname.visualstudio.com/DefaultCollection/MyRepo , the correct repositoryURL for us on VSTS is https://[secure]@companyname.visualstudio.com/DefaultCollection/_git/MyRepo .

The error that we had is like:

fatal: Authentication failed for 'https://[secure]@companyname.visualstudio.com/DefaultCollection/MyRepo.git/

2018-04-10T12:00:43.9886799Z { SemanticReleaseError: The push permission to the Git repository is required.
2018-04-10T12:00:43.9903773Z     at module.exports (/vsts/agent/_work/1/s/node_modules/semantic-release/lib/get-error.js:6:10)
2018-04-10T12:00:43.9922450Z     at run (/vsts/agent/_work/1/s/node_modules/semantic-release/index.js:51:11)
2018-04-10T12:00:43.9940073Z     at <anonymous>
2018-04-10T12:00:43.9956623Z     at process._tickCallback (internal/process/next_tick.js:188:7)
2018-04-10T12:00:43.9973157Z   name: 'SemanticReleaseError',
2018-04-10T12:00:43.9990080Z   code: 'EGITNOPERMISSION',
2018-04-10T12:00:44.0008210Z   details: '**semantic-release** cannot push the version tag to the branch `BUILD` on remote Git repository.\n\nPlease refer to the [authentication configuration documentation](https://github.com/semantic-release/semantic-release/blob/caribou/docs/usage/ci-configuration.md#authentication) to configure the Git credentials on your CI environment.',
2018-04-10T12:00:44.0027178Z   semanticRelease: true }

and the URL that we need is https://[secure]@companyname.visualstudio.com/DefaultCollection/_git/MyRepo

This issue happen at your version (8.3.1) with semantic-release version (15.1.5)

`.git` at the end of the URL is dropped with `toString()`

const gitUrlParse = require('git-url-parse');

gitUrlParse('[email protected]:IonicaBizau/node-git-url-parse.git').toString();
// => [email protected]:IonicaBizau/node-git-url-parse
// => Should be [email protected]:IonicaBizau/node-git-url-parse.git

gitUrlParse('https://github.com/IonicaBizau/node-git-url-parse.git').toString();
// => https://github.com/IonicaBizau/node-git-url-parse
// => Should be https://github.com/IonicaBizau/node-git-url-parse.git

It seems to be due to the parsing that doesn't set git_suffix to true when the URL ends with .git:

> gitUrlParse('https://github.com/IonicaBizau/node-git-url-parse.git')
/*
{ protocols: [ 'https' ],
  protocol: 'https',
  port: null,
  resource: 'github.com',
  user: '',
  pathname: '/IonicaBizau/node-git-url-parse.git',
  hash: '',
  search: '',
  href: 'https://github.com/IonicaBizau/node-git-url-parse.git',
  token: '',
  toString: [Function],
  source: 'github.com',
  name: 'node-git-url-parse',
  owner: 'IonicaBizau',
  git_suffix: false,
  ref: '',
  filepathtype: '',
  filepath: '',
  organization: 'IonicaBizau',
  full_name: 'IonicaBizau/node-git-url-parse' }
*/

Basic auth is omitted when calling `toString('http')` or `toString('https')`

When parsing a URL with a basic auth (i.g. http://user:[email protected]) the auth part is correctly parsed in the user prop:

gitUrlParse('http://user:[email protected]/aaaa/bbb');
/*
{
  ...
  user: 'user:pass',
  ...
}
*/

However when calling toString('http') or toString('https') on the result object the stringified URL miss the basic auth part:

gitUrlParse('http://user:[email protected]/aaaa/bbb').toString('https')
// => Result: 'https://github.com/aaaa/bbb'
// => Should be 'https://user:[email protected]/aaaa/bbb'

`npm test` fails on windows

npm test command fails on Windows 10 with node 8.

Error:

$ npm test

> [email protected] test C:\Users\Gyandeep\WebstormProjects\git-url-parse
> node test

C:\Users\Gyandeep\WebstormProjects\git-url-parse\node_modules\emoji-logger\lib\index.js:74
        throw new Err("There is no such icon: " + icon, "NO_SUCH_ICON");
        ^

Error: There is no such icon: heavyCheckMark
    at new Err (C:\Users\Gyandeep\WebstormProjects\git-url-parse\node_modules\err\lib\index.js:19:17)
    at Function.emojiLogger.add (C:\Users\Gyandeep\WebstormProjects\git-url-parse\node_modules\emoji-logger\lib\index.js:74:15)
    at Object.<anonymous> (C:\Users\Gyandeep\WebstormProjects\git-url-parse\node_modules\emoji-logger\lib\index.js:88:13)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.