pax_global_header00006660000000000000000000000064131242666100014513gustar00rootroot0000000000000052 comment=88da66d167a6d896c129d97209ce9864c201d067 hosted-git-info-2.5.0/000077500000000000000000000000001312426661000145175ustar00rootroot00000000000000hosted-git-info-2.5.0/.gitignore000066400000000000000000000000501312426661000165020ustar00rootroot00000000000000*~ .# node_modules .nyc_output coverage hosted-git-info-2.5.0/.npmignore000066400000000000000000000000211312426661000165070ustar00rootroot00000000000000test .travis.yml hosted-git-info-2.5.0/.travis.yml000066400000000000000000000000771312426661000166340ustar00rootroot00000000000000language: node_js sudo: false node_js: - "7" - "6" - "4" hosted-git-info-2.5.0/LICENSE000066400000000000000000000013351312426661000155260ustar00rootroot00000000000000Copyright (c) 2015, Rebecca Turner Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. hosted-git-info-2.5.0/README.md000066400000000000000000000077461312426661000160140ustar00rootroot00000000000000# hosted-git-info This will let you identify and transform various git hosts URLs between protocols. It also can tell you what the URL is for the raw path for particular file for direct access without git. ## Example ```javascript var hostedGitInfo = require("hosted-git-info") var info = hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git", opts) /* info looks like: { type: "github", domain: "github.com", user: "npm", project: "hosted-git-info" } */ ``` If the URL can't be matched with a git host, `null` will be returned. We can match git, ssh and https urls. Additionally, we can match ssh connect strings (`git@github.com:npm/hosted-git-info`) and shortcuts (eg, `github:npm/hosted-git-info`). Github specifically, is detected in the case of a third, unprefixed, form: `npm/hosted-git-info`. If it does match, the returned object has properties of: * info.type -- The short name of the service * info.domain -- The domain for git protocol use * info.user -- The name of the user/org on the git host * info.project -- The name of the project on the git host ## Version Contract The major version will be bumped any time… * The constructor stops accepting URLs that it previously accepted. * A method is removed. * A method can no longer accept the number and type of arguments it previously accepted. * A method can return a different type than it currently returns. Implications: * I do not consider the specific format of the urls returned from, say `.https()` to be a part of the contract. The contract is that it will return a string that can be used to fetch the repo via HTTPS. But what that string looks like, specifically, can change. * Dropping support for a hosted git provider would constitute a breaking change. ## Usage ### var info = hostedGitInfo.fromUrl(gitSpecifier[, options]) * *gitSpecifer* is a URL of a git repository or a SCP-style specifier of one. * *options* is an optional object. It can have the following properties: * *noCommittish* — If true then committishes won't be included in generated URLs. * *noGitPlus* — If true then `git+` won't be prefixed on URLs. ## Methods All of the methods take the same options as the `fromUrl` factory. Options provided to a method override those provided to the constructor. * info.file(path, opts) Given the path of a file relative to the repository, returns a URL for directly fetching it from the githost. If no committish was set then `master` will be used as the default. For example `hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git#v1.0.0").file("package.json")` would return `https://raw.githubusercontent.com/npm/hosted-git-info/v1.0.0/package.json` * info.shortcut(opts) eg, `github:npm/hosted-git-info` * info.browse(opts) eg, `https://github.com/npm/hosted-git-info/tree/v1.2.0` * info.bugs(opts) eg, `https://github.com/npm/hosted-git-info/issues` * info.docs(opts) eg, `https://github.com/npm/hosted-git-info/tree/v1.2.0#readme` * info.https(opts) eg, `git+https://github.com/npm/hosted-git-info.git` * info.sshurl(opts) eg, `git+ssh://git@github.com/npm/hosted-git-info.git` * info.ssh(opts) eg, `git@github.com:npm/hosted-git-info.git` * info.path(opts) eg, `npm/hosted-git-info` * info.tarball(opts) eg, `https://github.com/npm/hosted-git-info/archive/v1.2.0.tar.gz` * info.getDefaultRepresentation() Returns the default output type. The default output type is based on the string you passed in to be parsed * info.toString(opts) Uses the getDefaultRepresentation to call one of the other methods to get a URL for this resource. As such `hostedGitInfo.fromUrl(url).toString()` will give you a normalized version of the URL that still uses the same protocol. Shortcuts will still be returned as shortcuts, but the special case github form of `org/project` will be normalized to `github:org/project`. SSH connect strings will be normalized into `git+ssh` URLs. ## Supported hosts Currently this supports Github, Bitbucket and Gitlab. Pull requests for additional hosts welcome. hosted-git-info-2.5.0/git-host-info.js000066400000000000000000000061721312426661000175520ustar00rootroot00000000000000'use strict' var gitHosts = module.exports = { github: { // First two are insecure and generally shouldn't be used any more, but // they are still supported. 'protocols': [ 'git', 'http', 'git+ssh', 'git+https', 'ssh', 'https' ], 'domain': 'github.com', 'treepath': 'tree', 'filetemplate': 'https://{auth@}raw.githubusercontent.com/{user}/{project}/{committish}/{path}', 'bugstemplate': 'https://{domain}/{user}/{project}/issues', 'gittemplate': 'git://{auth@}{domain}/{user}/{project}.git{#committish}', 'tarballtemplate': 'https://{domain}/{user}/{project}/archive/{committish}.tar.gz' }, bitbucket: { 'protocols': [ 'git+ssh', 'git+https', 'ssh', 'https' ], 'domain': 'bitbucket.org', 'treepath': 'src', 'tarballtemplate': 'https://{domain}/{user}/{project}/get/{committish}.tar.gz' }, gitlab: { 'protocols': [ 'git+ssh', 'git+https', 'ssh', 'https' ], 'domain': 'gitlab.com', 'treepath': 'tree', 'docstemplate': 'https://{domain}/{user}/{project}{/tree/committish}#README', 'bugstemplate': 'https://{domain}/{user}/{project}/issues', 'tarballtemplate': 'https://{domain}/{user}/{project}/repository/archive.tar.gz?ref={committish}' }, gist: { 'protocols': [ 'git', 'git+ssh', 'git+https', 'ssh', 'https' ], 'domain': 'gist.github.com', 'pathmatch': /^[/](?:([^/]+)[/])?([a-z0-9]+)(?:[.]git)?$/, 'filetemplate': 'https://gist.githubusercontent.com/{user}/{project}/raw{/committish}/{path}', 'bugstemplate': 'https://{domain}/{project}', 'gittemplate': 'git://{domain}/{project}.git{#committish}', 'sshtemplate': 'git@{domain}:/{project}.git{#committish}', 'sshurltemplate': 'git+ssh://git@{domain}/{project}.git{#committish}', 'browsetemplate': 'https://{domain}/{project}{/committish}', 'docstemplate': 'https://{domain}/{project}{/committish}', 'httpstemplate': 'git+https://{domain}/{project}.git{#committish}', 'shortcuttemplate': '{type}:{project}{#committish}', 'pathtemplate': '{project}{#committish}', 'tarballtemplate': 'https://{domain}/{user}/{project}/archive/{committish}.tar.gz' } } var gitHostDefaults = { 'sshtemplate': 'git@{domain}:{user}/{project}.git{#committish}', 'sshurltemplate': 'git+ssh://git@{domain}/{user}/{project}.git{#committish}', 'browsetemplate': 'https://{domain}/{user}/{project}{/tree/committish}', 'docstemplate': 'https://{domain}/{user}/{project}{/tree/committish}#readme', 'httpstemplate': 'git+https://{auth@}{domain}/{user}/{project}.git{#committish}', 'filetemplate': 'https://{domain}/{user}/{project}/raw/{committish}/{path}', 'shortcuttemplate': '{type}:{user}/{project}{#committish}', 'pathtemplate': '{user}/{project}{#committish}', 'pathmatch': /^[/]([^/]+)[/]([^/]+?)(?:[.]git|[/])?$/ } Object.keys(gitHosts).forEach(function (name) { Object.keys(gitHostDefaults).forEach(function (key) { if (gitHosts[name][key]) return gitHosts[name][key] = gitHostDefaults[key] }) gitHosts[name].protocols_re = RegExp('^(' + gitHosts[name].protocols.map(function (protocol) { return protocol.replace(/([\\+*{}()[\]$^|])/g, '\\$1') }).join('|') + '):$') }) hosted-git-info-2.5.0/git-host.js000066400000000000000000000061771312426661000166260ustar00rootroot00000000000000'use strict' var gitHosts = require('./git-host-info.js') var extend = Object.assign || require('util')._extend var GitHost = module.exports = function (type, user, auth, project, committish, defaultRepresentation, opts) { var gitHostInfo = this gitHostInfo.type = type Object.keys(gitHosts[type]).forEach(function (key) { gitHostInfo[key] = gitHosts[type][key] }) gitHostInfo.user = user gitHostInfo.auth = auth gitHostInfo.project = project gitHostInfo.committish = committish gitHostInfo.default = defaultRepresentation gitHostInfo.opts = opts || {} } GitHost.prototype = {} GitHost.prototype.hash = function () { return this.committish ? '#' + this.committish : '' } GitHost.prototype._fill = function (template, opts) { if (!template) return var vars = extend({}, opts) opts = extend(extend({}, this.opts), opts) var self = this Object.keys(this).forEach(function (key) { if (self[key] != null && vars[key] == null) vars[key] = self[key] }) var rawAuth = vars.auth var rawComittish = vars.committish Object.keys(vars).forEach(function (key) { vars[key] = encodeURIComponent(vars[key]) }) vars['auth@'] = rawAuth ? rawAuth + '@' : '' if (opts.noCommittish) { vars['#committish'] = '' vars['/tree/committish'] = '' vars['/comittish'] = '' vars.comittish = '' } else { vars['#committish'] = rawComittish ? '#' + rawComittish : '' vars['/tree/committish'] = vars.committish ? '/' + vars.treepath + '/' + vars.committish : '' vars['/committish'] = vars.committish ? '/' + vars.committish : '' vars.committish = vars.committish || 'master' } var res = template Object.keys(vars).forEach(function (key) { res = res.replace(new RegExp('[{]' + key + '[}]', 'g'), vars[key]) }) if (opts.noGitPlus) { return res.replace(/^git[+]/, '') } else { return res } } GitHost.prototype.ssh = function (opts) { return this._fill(this.sshtemplate, opts) } GitHost.prototype.sshurl = function (opts) { return this._fill(this.sshurltemplate, opts) } GitHost.prototype.browse = function (opts) { return this._fill(this.browsetemplate, opts) } GitHost.prototype.docs = function (opts) { return this._fill(this.docstemplate, opts) } GitHost.prototype.bugs = function (opts) { return this._fill(this.bugstemplate, opts) } GitHost.prototype.https = function (opts) { return this._fill(this.httpstemplate, opts) } GitHost.prototype.git = function (opts) { return this._fill(this.gittemplate, opts) } GitHost.prototype.shortcut = function (opts) { return this._fill(this.shortcuttemplate, opts) } GitHost.prototype.path = function (opts) { return this._fill(this.pathtemplate, opts) } GitHost.prototype.tarball = function (opts) { return this._fill(this.tarballtemplate, opts) } GitHost.prototype.file = function (P, opts) { return this._fill(this.filetemplate, extend({ path: P.replace(/^[/]+/g, '') }, opts)) } GitHost.prototype.getDefaultRepresentation = function () { return this.default } GitHost.prototype.toString = function (opts) { return (this[this.default] || this.sshurl).call(this, opts) } hosted-git-info-2.5.0/index.js000066400000000000000000000075661312426661000162020ustar00rootroot00000000000000'use strict' var url = require('url') var gitHosts = require('./git-host-info.js') var GitHost = module.exports = require('./git-host.js') var protocolToRepresentationMap = { 'git+ssh': 'sshurl', 'git+https': 'https', 'ssh': 'sshurl', 'git': 'git' } function protocolToRepresentation (protocol) { if (protocol.substr(-1) === ':') protocol = protocol.slice(0, -1) return protocolToRepresentationMap[protocol] || protocol } var authProtocols = { 'git:': true, 'https:': true, 'git+https:': true, 'http:': true, 'git+http:': true } var cache = {} module.exports.fromUrl = function (giturl, opts) { var key = giturl + JSON.stringify(opts || {}) if (!(key in cache)) { cache[key] = fromUrl(giturl, opts) } return cache[key] } function fromUrl (giturl, opts) { if (giturl == null || giturl === '') return var url = fixupUnqualifiedGist( isGitHubShorthand(giturl) ? 'github:' + giturl : giturl ) var parsed = parseGitUrl(url) var shortcutMatch = url.match(new RegExp('^([^:]+):(?:(?:[^@:]+(?:[^@]+)?@)?([^/]*))[/](.+?)(?:[.]git)?($|#)')) var matches = Object.keys(gitHosts).map(function (gitHostName) { try { var gitHostInfo = gitHosts[gitHostName] var auth = null if (parsed.auth && authProtocols[parsed.protocol]) { auth = decodeURIComponent(parsed.auth) } var committish = parsed.hash ? decodeURIComponent(parsed.hash.substr(1)) : null var user = null var project = null var defaultRepresentation = null if (shortcutMatch && shortcutMatch[1] === gitHostName) { user = shortcutMatch[2] && decodeURIComponent(shortcutMatch[2]) project = decodeURIComponent(shortcutMatch[3]) defaultRepresentation = 'shortcut' } else { if (parsed.host !== gitHostInfo.domain) return if (!gitHostInfo.protocols_re.test(parsed.protocol)) return if (!parsed.path) return var pathmatch = gitHostInfo.pathmatch var matched = parsed.path.match(pathmatch) if (!matched) return if (matched[1] != null) user = decodeURIComponent(matched[1].replace(/^:/, '')) if (matched[2] != null) project = decodeURIComponent(matched[2]) defaultRepresentation = protocolToRepresentation(parsed.protocol) } return new GitHost(gitHostName, user, auth, project, committish, defaultRepresentation, opts) } catch (ex) { if (!(ex instanceof URIError)) throw ex } }).filter(function (gitHostInfo) { return gitHostInfo }) if (matches.length !== 1) return return matches[0] } function isGitHubShorthand (arg) { // Note: This does not fully test the git ref format. // See https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html // // The only way to do this properly would be to shell out to // git-check-ref-format, and as this is a fast sync function, // we don't want to do that. Just let git fail if it turns // out that the commit-ish is invalid. // GH usernames cannot start with . or - 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)?(#.*)?$/) if (!matched) return url.parse(giturl) return { protocol: 'git+ssh:', slashes: true, auth: matched[1], host: matched[2], port: null, hostname: matched[2], hash: matched[4], search: null, query: null, pathname: '/' + matched[3], path: '/' + matched[3], href: 'git+ssh://' + matched[1] + '@' + matched[2] + '/' + matched[3] + (matched[4] || '') } } hosted-git-info-2.5.0/package.json000066400000000000000000000014511312426661000170060ustar00rootroot00000000000000{ "name": "hosted-git-info", "version": "2.5.0", "description": "Provides metadata and conversions from repository urls for Github, Bitbucket and Gitlab", "main": "index.js", "repository": { "type": "git", "url": "git+https://github.com/npm/hosted-git-info.git" }, "keywords": [ "git", "github", "bitbucket", "gitlab" ], "author": "Rebecca Turner (http://re-becca.org)", "license": "ISC", "bugs": { "url": "https://github.com/npm/hosted-git-info/issues" }, "homepage": "https://github.com/npm/hosted-git-info", "scripts": { "test": "standard && tap -J --coverage test/*.js" }, "devDependencies": { "standard": "^9.0.2", "tap": "^10.3.0" }, "files": [ "index.js", "git-host.js", "git-host-info.js" ] } hosted-git-info-2.5.0/test/000077500000000000000000000000001312426661000154765ustar00rootroot00000000000000hosted-git-info-2.5.0/test/basic.js000066400000000000000000000044161312426661000171220ustar00rootroot00000000000000'use strict' var HostedGit = require('../index') var test = require('tap').test test('basic', function (t) { t.is(HostedGit.fromUrl('https://google.com'), undefined, 'null on failure') t.is(HostedGit.fromUrl('https://github.com/abc/def').getDefaultRepresentation(), 'https', 'match https urls') t.is(HostedGit.fromUrl('https://github.com/abc/def/').getDefaultRepresentation(), 'https', 'match URLs with a trailing slash') t.is(HostedGit.fromUrl('ssh://git@github.com/abc/def').getDefaultRepresentation(), 'sshurl', 'match ssh urls') t.is(HostedGit.fromUrl('git+ssh://git@github.com/abc/def').getDefaultRepresentation(), 'sshurl', 'match git+ssh urls') t.is(HostedGit.fromUrl('git+https://github.com/abc/def').getDefaultRepresentation(), 'https', 'match git+https urls') t.is(HostedGit.fromUrl('git@github.com:abc/def').getDefaultRepresentation(), 'sshurl', 'match ssh connect strings') t.is(HostedGit.fromUrl('git://github.com/abc/def').getDefaultRepresentation(), 'git', 'match git urls') t.is(HostedGit.fromUrl('github:abc/def').getDefaultRepresentation(), 'shortcut', 'match shortcuts') t.is(HostedGit.fromUrl('git+ssh://git@nothosted.com/abc/def'), undefined, 'non-hosted URLs get undefined response') t.is(HostedGit.fromUrl('git://nothosted.com'), undefined, 'non-hosted empty URLs get undefined response') t.is(HostedGit.fromUrl('git://github.com/balderdashy/waterline-%s.git'), undefined, 'invalid URLs get undefined response') t.is(HostedGit.fromUrl('git://github.com'), undefined, 'Invalid hosted URLs get undefined response') t.is(HostedGit.fromUrl('dEf/AbC').https(), 'git+https://github.com/dEf/AbC.git', 'mixed case shortcut') t.is(HostedGit.fromUrl('gitlab:dEf/AbC').https(), 'git+https://gitlab.com/dEf/AbC.git', 'mixed case prefixed shortcut') t.is(HostedGit.fromUrl('gitlab:dEf/AbC.git').https(), 'git+https://gitlab.com/dEf/AbC.git', 'mixed case prefixed shortcut') t.is(HostedGit.fromUrl('git://github.com/dEf/AbC.git').https(), 'git+https://github.com/dEf/AbC.git', 'mixed case url') t.is(HostedGit.fromUrl('gist:123').https(), 'git+https://gist.github.com/123.git', 'non-user shortcut') t.is(HostedGit.fromUrl('git+https://github.com:foo/repo.git#master').https(), 'git+https://github.com/foo/repo.git#master', 'scp style urls are upgraded') t.end() }) hosted-git-info-2.5.0/test/bitbucket-https-with-embedded-auth.js000066400000000000000000000016311312426661000246100ustar00rootroot00000000000000'use strict' var HostedGit = require('../index') var test = require('tap').test test('Bitbucket HTTPS URLs with embedded auth', function (t) { t.is( HostedGit.fromUrl('https://user:pass@bitbucket.org/user/repo.git').toString(), 'git+https://user:pass@bitbucket.org/user/repo.git', 'credentials were included in URL' ) t.is( HostedGit.fromUrl('https://user:pass@bitbucket.org/user/repo').toString(), 'git+https://user:pass@bitbucket.org/user/repo.git', 'credentials were included in URL' ) t.is( HostedGit.fromUrl('git+https://user:pass@bitbucket.org/user/repo.git').toString(), 'git+https://user:pass@bitbucket.org/user/repo.git', 'credentials were included in URL' ) t.is( HostedGit.fromUrl('git+https://user:pass@bitbucket.org/user/repo').toString(), 'git+https://user:pass@bitbucket.org/user/repo.git', 'credentials were included in URL' ) t.end() }) hosted-git-info-2.5.0/test/bitbucket.js000066400000000000000000000023351312426661000200130ustar00rootroot00000000000000'use strict' var HostedGit = require('../index') var test = require('tap').test test('fromUrl(bitbucket url)', function (t) { function verify (host, label, branch) { var hostinfo = HostedGit.fromUrl(host) var hash = branch ? '#' + branch : '' t.ok(hostinfo, label) if (!hostinfo) return t.is(hostinfo.https(), 'git+https://bitbucket.org/111/222.git' + hash, label + ' -> https') t.is(hostinfo.browse(), 'https://bitbucket.org/111/222' + (branch ? '/src/' + branch : ''), label + ' -> browse') t.is(hostinfo.docs(), 'https://bitbucket.org/111/222' + (branch ? '/src/' + branch : '') + '#readme', label + ' -> docs') t.is(hostinfo.ssh(), 'git@bitbucket.org:111/222.git' + hash, label + ' -> ssh') t.is(hostinfo.sshurl(), 'git+ssh://git@bitbucket.org/111/222.git' + hash, label + ' -> sshurl') t.is(hostinfo.shortcut(), 'bitbucket:111/222' + hash, label + ' -> shortcut') t.is(hostinfo.file('C'), 'https://bitbucket.org/111/222/raw/' + (branch || 'master') + '/C', label + ' -> file') t.is(hostinfo.tarball(), 'https://bitbucket.org/111/222/get/' + (branch || 'master') + '.tar.gz', label + ' -> tarball') } require('./lib/standard-tests')(verify, 'bitbucket.org', 'bitbucket') t.end() }) hosted-git-info-2.5.0/test/gist.js000066400000000000000000000041031312426661000170000ustar00rootroot00000000000000'use strict' var HostedGit = require('../index') var test = require('tap').test test('fromUrl(gist url)', function (t) { function verify (host, label, branch) { var hostinfo = HostedGit.fromUrl(host) var hash = branch ? '#' + branch : '' t.ok(hostinfo, label) if (!hostinfo) return t.is(hostinfo.https(), 'git+https://gist.github.com/222.git' + hash, label + ' -> https') t.is(hostinfo.git(), 'git://gist.github.com/222.git' + hash, label + ' -> git') t.is(hostinfo.browse(), 'https://gist.github.com/222' + (branch ? '/' + branch : ''), label + ' -> browse') t.is(hostinfo.bugs(), 'https://gist.github.com/222', label + ' -> bugs') t.is(hostinfo.docs(), 'https://gist.github.com/222' + (branch ? '/' + branch : ''), label + ' -> docs') t.is(hostinfo.ssh(), 'git@gist.github.com:/222.git' + hash, label + ' -> ssh') t.is(hostinfo.sshurl(), 'git+ssh://git@gist.github.com/222.git' + hash, label + ' -> sshurl') t.is(hostinfo.shortcut(), 'gist:222' + hash, label + ' -> shortcut') if (hostinfo.user) { t.is(hostinfo.file('C'), 'https://gist.githubusercontent.com/111/222/raw/' + (branch ? branch + '/' : '') + 'C', label + ' -> file') t.is(hostinfo.tarball(), 'https://gist.github.com/111/222/archive/' + (branch || 'master') + '.tar.gz', label + ' -> tarball') } } verify('git@gist.github.com:222.git', 'git@') var hostinfo = HostedGit.fromUrl('git@gist.github.com:/ef860c7z5e0de3179341.git') if (t.ok(hostinfo, 'git@hex')) { t.is(hostinfo.https(), 'git+https://gist.github.com/ef860c7z5e0de3179341.git', 'git@hex -> https') } verify('git@gist.github.com:/222.git', 'git@/') verify('git://gist.github.com/222', 'git') verify('git://gist.github.com/222.git', 'git.git') verify('git://gist.github.com/222#branch', 'git#branch', 'branch') verify('git://gist.github.com/222.git#branch', 'git.git#branch', 'branch') 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() }) hosted-git-info-2.5.0/test/github.js000066400000000000000000000037541312426661000173270ustar00rootroot00000000000000'use strict' var HostedGit = require('../index') var test = require('tap').test test('fromUrl(github url)', function (t) { function verify (host, label, branch) { var hostinfo = HostedGit.fromUrl(host) var hash = branch ? '#' + branch : '' t.ok(hostinfo, label) if (!hostinfo) return t.is(hostinfo.https(), 'git+https://github.com/111/222.git' + hash, label + ' -> https') t.is(hostinfo.git(), 'git://github.com/111/222.git' + hash, label + ' -> git') t.is(hostinfo.browse(), 'https://github.com/111/222' + (branch ? '/tree/' + branch : ''), label + ' -> browse') t.is(hostinfo.bugs(), 'https://github.com/111/222/issues', label + ' -> bugs') t.is(hostinfo.docs(), 'https://github.com/111/222' + (branch ? '/tree/' + branch : '') + '#readme', label + ' -> docs') t.is(hostinfo.ssh(), 'git@github.com:111/222.git' + hash, label + ' -> ssh') t.is(hostinfo.sshurl(), 'git+ssh://git@github.com/111/222.git' + hash, label + ' -> sshurl') t.is(hostinfo.shortcut(), 'github:111/222' + hash, label + ' -> shortcut') t.is(hostinfo.file('C'), 'https://raw.githubusercontent.com/111/222/' + (branch || 'master') + '/C', label + ' -> file') t.is(hostinfo.tarball(), 'https://github.com/111/222/archive/' + (branch || 'master') + '.tar.gz', label + ' -> tarball') } // github shorturls verify('111/222', 'github-short') verify('111/222#branch', 'github-short#branch', 'branch') // insecure protocols verify('git://github.com/111/222', 'git') verify('git://github.com/111/222.git', 'git.git') verify('git://github.com/111/222#branch', 'git#branch', 'branch') verify('git://github.com/111/222.git#branch', 'git.git#branch', 'branch') verify('http://github.com/111/222', 'http') verify('http://github.com/111/222.git', 'http.git') verify('http://github.com/111/222#branch', 'http#branch', 'branch') verify('http://github.com/111/222.git#branch', 'http.git#branch', 'branch') require('./lib/standard-tests')(verify, 'github.com', 'github') t.end() }) hosted-git-info-2.5.0/test/gitlab.js000066400000000000000000000023141312426661000172760ustar00rootroot00000000000000'use strict' var HostedGit = require('../index') var test = require('tap').test test('fromUrl(gitlab url)', function (t) { function verify (host, label, branch) { var hostinfo = HostedGit.fromUrl(host) var hash = branch ? '#' + branch : '' t.ok(hostinfo, label) if (!hostinfo) return t.is(hostinfo.https(), 'git+https://gitlab.com/111/222.git' + hash, label + ' -> https') t.is(hostinfo.browse(), 'https://gitlab.com/111/222' + (branch ? '/tree/' + branch : ''), label + ' -> browse') t.is(hostinfo.docs(), 'https://gitlab.com/111/222' + (branch ? '/tree/' + branch : '') + '#README', label + ' -> docs') t.is(hostinfo.ssh(), 'git@gitlab.com:111/222.git' + hash, label + ' -> ssh') t.is(hostinfo.sshurl(), 'git+ssh://git@gitlab.com/111/222.git' + hash, label + ' -> sshurl') t.is(hostinfo.shortcut(), 'gitlab:111/222' + hash, label + ' -> shortcut') t.is(hostinfo.file('C'), 'https://gitlab.com/111/222/raw/' + (branch || 'master') + '/C', label + ' -> file') t.is(hostinfo.tarball(), 'https://gitlab.com/111/222/repository/archive.tar.gz?ref=' + (branch || 'master'), label + ' -> tarball') } require('./lib/standard-tests')(verify, 'gitlab.com', 'gitlab') t.end() }) hosted-git-info-2.5.0/test/https-with-inline-auth.js000066400000000000000000000041701312426661000223640ustar00rootroot00000000000000'use strict' var HostedGit = require('../index') var test = require('tap').test test('HTTPS GitHub URL with embedded auth -- generally not a good idea', function (t) { function verify (host, label, branch) { var hostinfo = HostedGit.fromUrl(host) var hash = branch ? '#' + branch : '' t.ok(hostinfo, label) if (!hostinfo) return t.is(hostinfo.https(), 'git+https://user:pass@github.com/111/222.git' + hash, label + ' -> https') t.is(hostinfo.git(), 'git://user:pass@github.com/111/222.git' + hash, label + ' -> git') t.is(hostinfo.browse(), 'https://github.com/111/222' + (branch ? '/tree/' + branch : ''), label + ' -> browse') t.is(hostinfo.bugs(), 'https://github.com/111/222/issues', label + ' -> bugs') t.is(hostinfo.docs(), 'https://github.com/111/222' + (branch ? '/tree/' + branch : '') + '#readme', label + ' -> docs') t.is(hostinfo.ssh(), 'git@github.com:111/222.git' + hash, label + ' -> ssh') t.is(hostinfo.sshurl(), 'git+ssh://git@github.com/111/222.git' + hash, label + ' -> sshurl') t.is(hostinfo.shortcut(), 'github:111/222' + hash, label + ' -> shortcut') t.is(hostinfo.file('C'), 'https://user:pass@raw.githubusercontent.com/111/222/' + (branch || 'master') + '/C', label + ' -> file') } // insecure protocols verify('git://user:pass@github.com/111/222', 'git') verify('git://user:pass@github.com/111/222.git', 'git.git') verify('git://user:pass@github.com/111/222#branch', 'git#branch', 'branch') verify('git://user:pass@github.com/111/222.git#branch', 'git.git#branch', 'branch') verify('https://user:pass@github.com/111/222', 'https') verify('https://user:pass@github.com/111/222.git', 'https.git') verify('https://user:pass@github.com/111/222#branch', 'https#branch', 'branch') verify('https://user:pass@github.com/111/222.git#branch', 'https.git#branch', 'branch') verify('http://user:pass@github.com/111/222', 'http') verify('http://user:pass@github.com/111/222.git', 'http.git') verify('http://user:pass@github.com/111/222#branch', 'http#branch', 'branch') verify('http://user:pass@github.com/111/222.git#branch', 'http.git#branch', 'branch') t.end() }) hosted-git-info-2.5.0/test/lib/000077500000000000000000000000001312426661000162445ustar00rootroot00000000000000hosted-git-info-2.5.0/test/lib/standard-tests.js000066400000000000000000000026311312426661000215440ustar00rootroot00000000000000'use strict' module.exports = function (verify, domain, shortname) { verify('https://' + domain + '/111/222', 'https') verify('https://' + domain + '/111/222.git', 'https.git') verify('https://' + domain + '/111/222#branch', 'https#branch', 'branch') verify('https://' + domain + '/111/222.git#branch', 'https.git#branch', 'branch') verify('git+https://' + domain + '/111/222', 'git+https') verify('git+https://' + domain + '/111/222.git', 'git+https.git') verify('git+https://' + domain + '/111/222#branch', 'git+https#branch', 'branch') verify('git+https://' + domain + '/111/222.git#branch', 'git+https.git#branch', 'branch') verify('git@' + domain + ':111/222', 'ssh') verify('git@' + domain + ':111/222.git', 'ssh.git') verify('git@' + domain + ':111/222#branch', 'ssh', 'branch') verify('git@' + domain + ':111/222.git#branch', 'ssh.git', 'branch') verify('git+ssh://git@' + domain + '/111/222', 'ssh url') verify('git+ssh://git@' + domain + '/111/222.git', 'ssh url.git') verify('git+ssh://git@' + domain + '/111/222#branch', 'ssh url#branch', 'branch') verify('git+ssh://git@' + domain + '/111/222.git#branch', 'ssh url.git#branch', 'branch') verify(shortname + ':111/222', 'shortcut') verify(shortname + ':111/222.git', 'shortcut.git') verify(shortname + ':111/222#branch', 'shortcut#branch', 'branch') verify(shortname + ':111/222.git#branch', 'shortcut.git#branch', 'branch') }