diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-04-10 13:12:00 +0300 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2015-04-10 13:24:08 +0300 |
commit | dd398e98a8eba27eeba84378200da3d078fdf980 (patch) | |
tree | 4a9d4e1ad986578d20bc77211a8368f8530e1d75 /node_modules | |
parent | 6b0f58877f37df9904490ffbaaad33862bd36dce (diff) |
hosted-git-info@2.1.1
Support round-tripping gist: shortcuts. gist: shorthand gets normalized
to remove the username (because all you need is the ID to clone). This
confuses url.parse(), which is used to parse out the git URL.
Diffstat (limited to 'node_modules')
-rw-r--r-- | node_modules/hosted-git-info/index.js | 14 | ||||
-rw-r--r-- | node_modules/hosted-git-info/package.json | 30 | ||||
-rw-r--r-- | node_modules/hosted-git-info/test/gist.js | 3 |
3 files changed, 23 insertions, 24 deletions
diff --git a/node_modules/hosted-git-info/index.js b/node_modules/hosted-git-info/index.js index 2c1f66592..fe510c905 100644 --- a/node_modules/hosted-git-info/index.js +++ b/node_modules/hosted-git-info/index.js @@ -23,7 +23,9 @@ var authProtocols = { module.exports.fromUrl = function (giturl) { if (giturl == null || giturl === '') return - var url = isGitHubShorthand(giturl) ? 'github:' + giturl : giturl + var url = fixupUnqualifiedGist( + isGitHubShorthand(giturl) ? 'github:' + giturl : giturl + ) var parsed = parseGitUrl(url) var matches = Object.keys(gitHosts).map(function (gitHostName) { var gitHostInfo = gitHosts[gitHostName] @@ -67,6 +69,16 @@ function isGitHubShorthand (arg) { return /^[^:@%/\s.-][^:@%/\s]*[/][^:@\s/%]+(?:#.*)?$/.test(arg) } +function fixupUnqualifiedGist (giturl) { + // necessary for round-tripping gists + var parsed = url.parse(giturl) + if (parsed.protocol === 'gist:' && parsed.host && !parsed.path) { + return parsed.protocol + '/' + parsed.host + } else { + return giturl + } +} + function parseGitUrl (giturl) { if (typeof giturl !== 'string') giturl = '' + giturl var matched = giturl.match(/^([^@]+)@([^:]+):[/]?((?:[^/]+[/])?[^/]+?)(?:[.]git)?(#.*)?$/) diff --git a/node_modules/hosted-git-info/package.json b/node_modules/hosted-git-info/package.json index e9782903d..b53862e21 100644 --- a/node_modules/hosted-git-info/package.json +++ b/node_modules/hosted-git-info/package.json @@ -1,6 +1,6 @@ { "name": "hosted-git-info", - "version": "2.1.0", + "version": "2.1.1", "description": "Provides metadata and conversions from repository urls for Github, Bitbucket and Gitlab", "main": "index.js", "repository": { @@ -30,26 +30,10 @@ "standard": "^3.3.2", "tap": "^0.4.13" }, - "gitHead": "0d2d6a8ae036bc485b32d1c519ae62a95e60ad9b", - "_id": "hosted-git-info@2.1.0", - "_shasum": "8b38742f56a7e2dafa3eb9ae85eea8b393f4c13e", - "_from": "hosted-git-info@>=2.1.0 <2.2.0", - "_npmVersion": "2.7.5", - "_nodeVersion": "1.6.2", - "_npmUser": { - "name": "iarna", - "email": "me@re-becca.org" - }, - "maintainers": [ - { - "name": "iarna", - "email": "me@re-becca.org" - } - ], - "dist": { - "shasum": "8b38742f56a7e2dafa3eb9ae85eea8b393f4c13e", - "tarball": "http://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.1.0.tgz" - }, - "directories": {}, - "_resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.1.0.tgz" + "readme": "# hosted-git-info\n\nThis will let you identify and transform various git hosts URLs between\nprotocols. It also can tell you what the URL is for the raw path for\nparticular file for direct access without git.\n\n## Usage\n\n```javascript\nvar hostedGitInfo = require(\"hosted-git-info\")\nvar info = hostedGitInfo.fromUrl(\"git@github.com:npm/hosted-git-info.git\")\n/* info looks like:\n{\n type: \"github\",\n domain: \"github.com\",\n user: \"npm\",\n project: \"hosted-git-info\"\n}\n*/\n```\n\nIf the URL can't be matched with a git host, `null` will be returned. We\ncan match git, ssh and https urls. Additionally, we can match ssh connect\nstrings (`git@github.com:npm/hosted-git-info`) and shortcuts (eg,\n`github:npm/hosted-git-info`). Github specifically, is detected in the case\nof a third, unprefixed, form: `npm/hosted-git-info`.\n\nIf it does match, the returned object has properties of:\n\n* info.type -- The short name of the service\n* info.domain -- The domain for git protocol use\n* info.user -- The name of the user/org on the git host\n* info.project -- The name of the project on the git host\n\nAnd methods of:\n\n* info.file(path)\n\nGiven the path of a file relative to the repository, returns a URL for\ndirectly fetching it from the githost. If no comittish was set then\n`master` will be used as the default.\n\nFor example `hostedGitInfo.fromUrl(\"git@github.com:npm/hosted-git-info.git#v1.0.0\").file(\"package.json\")`\nwould return `https://raw.githubusercontent.com/npm/hosted-git-info/v1.0.0/package.json`\n\n* info.shortcut()\n\neg, `github:npm/hosted-git-info`\n\n* info.browse()\n\neg, `https://github.com/npm/hosted-git-info/tree/v1.2.0`\n\n* info.bugs()\n\neg, `https://github.com/npm/hosted-git-info/issues`\n\n* info.docs()\n\neg, `https://github.com/npm/hosted-git-info/tree/v1.2.0#readme`\n\n* info.https()\n\neg, `git+https://github.com/npm/hosted-git-info.git`\n\n* info.sshurl()\n\neg, `git+ssh://git@github.com/npm/hosted-git-info.git`\n\n* info.ssh()\n\neg, `git@github.com:npm/hosted-git-info.git`\n\n* info.path()\n\neg, `npm/hosted-git-info`\n\n* info.getDefaultRepresentation()\n\nReturns the default output type. The default output type is based on the\nstring you passed in to be parsed\n\n* info.toString()\n\nUses the getDefaultRepresentation to call one of the other methods to get a URL for\nthis resource. As such `hostedGitInfo.fromUrl(url).toString()` will give\nyou a normalized version of the URL that still uses the same protocol.\n\nShortcuts will still be returned as shortcuts, but the special case github\nform of `org/project` will be normalized to `github:org/project`.\n\nSSH connect strings will be normalized into `git+ssh` URLs.\n\n\n## Supported hosts\n\nCurrently this supports Github, Bitbucket and Gitlab. Pull requests for\nadditional hosts welcome.\n\n", + "readmeFilename": "README.md", + "gitHead": "c4d4f14210372ef010cc8170dea84a0dedf504ca", + "_id": "hosted-git-info@2.1.1", + "_shasum": "915946c135ee5ff59437ef126f9bd6112192fcb0", + "_from": "hosted-git-info@>=2.1.1 <2.2.0" } diff --git a/node_modules/hosted-git-info/test/gist.js b/node_modules/hosted-git-info/test/gist.js index e844f04d3..cf36d3c8d 100644 --- a/node_modules/hosted-git-info/test/gist.js +++ b/node_modules/hosted-git-info/test/gist.js @@ -34,5 +34,8 @@ test('fromUrl(gist url)', function (t) { require('./lib/standard-tests')(verify, 'gist.github.com', 'gist') + verify(HostedGit.fromUrl('gist:111/222').toString(), 'round-tripped shortcut') + verify('gist:222', 'shortened shortcut') + t.end() }) |