Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hosted-git-info

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hosted-git-info - npm Package Compare versions

Comparing version 1.5.3 to 1.6.0

223

index.js

@@ -1,47 +0,56 @@

"use strict"
var url = require("url")
'use strict'
var url = require('url')
var GitHost = exports = module.exports = function (type, user, project, comittish) {
this.type = type
this.domain = gitHosts[type].domain
this.filetemplate = gitHosts[type].filetemplate
this.sshtemplate = gitHosts[type].sshtemplate
this.sshurltemplate = gitHosts[type].sshurltemplate
this.browsetemplate = gitHosts[type].browsetemplate
this.docstemplate = gitHosts[type].docstemplate
this.bugstemplate = gitHosts[type].bugstemplate
this.gittemplate = gitHosts[type].gittemplate
this.httpstemplate = gitHosts[type].httpstemplate
this.treepath = gitHosts[type].treepath
this.user = user
this.project = project
this.comittish = comittish
var GitHost = exports = module.exports = function (type, user, project, comittish, defaultType) {
var gitHostInfo = this
gitHostInfo.type = type
Object.keys(gitHosts[type]).forEach(function (key) {
gitHostInfo[key] = gitHosts[type][key]
})
gitHostInfo.user = user
gitHostInfo.project = project
gitHostInfo.comittish = comittish
gitHostInfo.default = defaultType
}
GitHost.prototype = {}
var protocolMap = {
'git+ssh': 'sshurl',
'git+https': 'https',
'ssh': 'sshurl',
'git': 'git'
}
function protocolToType (protocol) {
if (protocol.substr(-1) === ':') protocol = protocol.slice(0, -1)
return protocolMap[protocol] || protocol
}
exports.fromUrl = function (giturl) {
if (giturl == null || giturl == "") return
var parsed = parseGitUrl(maybeGitHubShorthand(giturl) ? "github:" + giturl : giturl)
var matches = Object.keys(gitHosts).map(function(V) {
if (giturl == null || giturl === '') return
var parsed = parseGitUrl(maybeGitHubShorthand(giturl) ? 'github:' + giturl : giturl)
var matches = Object.keys(gitHosts).map(function (V) {
var gitHost = gitHosts[V]
var comittish = parsed.hash ? decodeURIComponent(parsed.hash.substr(1)) : null
if (parsed.protocol == V + ":") {
if (parsed.protocol === V + ':') {
return new GitHost(V,
decodeURIComponent(parsed.host), decodeURIComponent(parsed.path.replace(/^[/](.*?)(?:[.]git)?$/, "$1")), comittish)
decodeURIComponent(parsed.host), decodeURIComponent(parsed.path.replace(/^[/](.*?)(?:[.]git)?$/, '$1')), comittish, 'shortcut')
}
if (parsed.host != gitHost.domain) return
if (! gitHost.protocols_re.test(parsed.protocol)) return
var matched = parsed.path.match(gitHost.pathmatch)
if (! matched) return
if (parsed.host !== gitHost.domain) return
if (!gitHost.protocols_re.test(parsed.protocol)) return
var pathmatch = gitHost.pathmatch || gitHostDefaults.pathmatch
var matched = parsed.path.match(pathmatch)
if (!matched) return
return new GitHost(
V,
matched[1]!=null && decodeURIComponent(matched[1]),
matched[2]!=null && decodeURIComponent(matched[2]),
comittish)
}).filter(function(V){ return V })
if (matches.length != 1) return
matched[1] != null && decodeURIComponent(matched[1]),
matched[2] != null && decodeURIComponent(matched[2]),
comittish,
protocolToType(parsed.protocol))
}).filter(function (V) { return V })
if (matches.length !== 1) return
return matches[0]
}
function maybeGitHubShorthand(arg) {
function maybeGitHubShorthand (arg) {
// Note: This does not fully test the git ref format.

@@ -59,7 +68,7 @@ // See https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html

var parseGitUrl = function (giturl) {
if (typeof giturl != "string") giturl = "" + giturl
if (typeof giturl !== 'string') giturl = '' + giturl
var matched = giturl.match(/^([^@]+)@([^:]+):[/]?((?:[^/]+[/])?[^/]+?)(?:[.]git)?(#.*)?$/)
if (! matched) return url.parse(giturl)
if (!matched) return url.parse(giturl)
return {
protocol: "git+ssh:",
protocol: 'git+ssh:',
slashes: true,

@@ -73,5 +82,5 @@ auth: matched[1],

query: null,
pathname: "/" + matched[3],
path: "/" + matched[3],
href: "git+ssh://" + matched[1] + "@" + matched[2] + "/" + matched[3] + (matched[4]||"")
pathname: '/' + matched[3],
path: '/' + matched[3],
href: 'git+ssh://' + matched[1] + '@' + matched[2] + '/' + matched[3] + (matched[4] || '')
}

@@ -81,8 +90,11 @@ }

var gitHostDefaults = {
"sshtemplate": "git@{domain}:{user}/{project}.git{#comittish}",
"sshurltemplate": "git+ssh://git@{domain}/{user}/{project}.git{#comittish}",
"browsetemplate": "https://{domain}/{user}/{project}{/tree/comittish}",
"docstemplate": "https://{domain}/{user}/{project}{/tree/comittish}#readme",
"httpstemplate": "https://{domain}/{user}/{project}.git{#comittish}",
"filetemplate": "https://{domain}/{user}/{project}/raw/{comittish}/{path}"
'sshtemplate': 'git@{domain}:{user}/{project}.git{#comittish}',
'sshurltemplate': 'git+ssh://git@{domain}/{user}/{project}.git{#comittish}',
'browsetemplate': 'https://{domain}/{user}/{project}{/tree/comittish}',
'docstemplate': 'https://{domain}/{user}/{project}{/tree/comittish}#readme',
'httpstemplate': 'https://{domain}/{user}/{project}.git{#comittish}',
'filetemplate': 'https://{domain}/{user}/{project}/raw/{comittish}/{path}',
'shortcuttemplate': '{type}:{user}/{project}{#comittish}',
'pathtemplate': '{user}/{project}{#comittish}',
'pathmatch': /^[/]([^/]+)[/]([^/]+?)(?:[.]git)?$/
}

@@ -93,72 +105,63 @@ var gitHosts = {

// they are still supported.
"protocols": [ "git", "http", "git+ssh", "git+https", "ssh", "https" ],
"domain": "github.com",
"pathmatch": /^[/]([^/]+)[/]([^/]+?)(?:[.]git)?$/,
"treepath": "tree",
"filetemplate": "https://raw.githubusercontent.com/{user}/{project}/{comittish}/{path}",
"bugstemplate": "https://{domain}/{user}/{project}/issues",
"gittemplate": "git://{domain}/{user}/{project}.git{#comittish}"
'protocols': [ 'git', 'http', 'git+ssh', 'git+https', 'ssh', 'https' ],
'domain': 'github.com',
'treepath': 'tree',
'filetemplate': 'https://raw.githubusercontent.com/{user}/{project}/{comittish}/{path}',
'bugstemplate': 'https://{domain}/{user}/{project}/issues',
'gittemplate': 'git://{domain}/{user}/{project}.git{#comittish}'
},
bitbucket: {
"protocols": [ "git+ssh", "git+https", "ssh", "https" ],
"domain": "bitbucket.org",
"pathmatch": /^[/]([^/]+)[/]([^/]+?)(?:[.]git)?$/,
"treepath": "src"
'protocols': [ 'git+ssh', 'git+https', 'ssh', 'https' ],
'domain': 'bitbucket.org',
'treepath': 'src'
},
gitlab: {
"protocols": [ "git+ssh", "git+https", "ssh", "https" ],
"domain": "gitlab.com",
"pathmatch": /^[/]([^/]+)[/]([^/]+?)(?:[.]git)?$/,
"treepath": "tree",
"docstemplate": "https://{domain}/{user}/{project}{/tree/comittish}#README",
"bugstemplate": "https://{domain}/{user}/{project}/issues"
'protocols': [ 'git+ssh', 'git+https', 'ssh', 'https' ],
'domain': 'gitlab.com',
'treepath': 'tree',
'docstemplate': 'https://{domain}/{user}/{project}{/tree/comittish}#README',
'bugstemplate': 'https://{domain}/{user}/{project}/issues'
},
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{/comittish}/{path}",
"bugstemplate": "https://{domain}/{project}",
"gittemplate": "git://{domain}/{project}.git{#comittish}",
"sshtemplate": "git@{domain}:/{project}.git{#comittish}",
"sshurltemplate": "git+ssh://git@{domain}/{project}.git{#comittish}",
"browsetemplate": "https://{domain}/{project}{/comittish}",
"docstemplate": "https://{domain}/{project}{/comittish}",
"httpstemplate": "https://{domain}/{project}.git{#comittish}",
},
'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{/comittish}/{path}',
'bugstemplate': 'https://{domain}/{project}',
'gittemplate': 'git://{domain}/{project}.git{#comittish}',
'sshtemplate': 'git@{domain}:/{project}.git{#comittish}',
'sshurltemplate': 'git+ssh://git@{domain}/{project}.git{#comittish}',
'browsetemplate': 'https://{domain}/{project}{/comittish}',
'docstemplate': 'https://{domain}/{project}{/comittish}',
'httpstemplate': 'https://{domain}/{project}.git{#comittish}',
'shortcuttemplate': '{type}:{project}{#comittish}',
'pathtemplate': '{project}{#comittish}'
}
}
Object.keys(gitHosts).forEach(function(host) {
gitHosts[host].protocols_re = RegExp("^(" +
gitHosts[host].protocols.map(function(P){
return P.replace(/([\\+*{}()\[\]$^|])/g, "\\$1")
}).join("|") + "):$")
Object.keys(gitHosts).forEach(function (host) {
gitHosts[host].protocols_re = RegExp('^(' +
gitHosts[host].protocols.map(function (P) {
return P.replace(/([\\+*{}()\[\]$^|])/g, '\\$1')
}).join('|') + '):$')
})
GitHost.prototype.shortcut = function () {
return this.type + ":" + this.path()
}
GitHost.prototype.hash = function () {
return this.comittish ? "#" + this.comittish : ""
return this.comittish ? '#' + this.comittish : ''
}
GitHost.prototype.path = function () {
return this.user + "/" + this.project + this.hash()
}
GitHost.prototype._fill = function (template, vars) {
if (!template) throw new Error("Tried to fill without template")
if (!template) return
if (!vars) vars = {}
var self = this
Object.keys(this).forEach(function(K){ if (self[K]!=null && vars[K]==null) vars[K] = self[K] })
Object.keys(this).forEach(function (K) { if (self[K] != null && vars[K] == null) vars[K] = self[K] })
var rawComittish = vars.comittish
Object.keys(vars).forEach(function(K){ (K[0]!='#') && (vars[K] = encodeURIComponent(vars[K])) })
vars["#comittish"] = rawComittish ? "#" + rawComittish : ""
vars["/tree/comittish"] = vars.comittish ? "/"+vars.treepath+"/" + vars.comittish : "",
vars["/comittish"] = vars.comittish ? "/" + vars.comittish : ""
vars.comittish = vars.comittish || "master"
Object.keys(vars).forEach(function (K) { (K[0] !== '#') && (vars[K] = encodeURIComponent(vars[K])) })
vars['#comittish'] = rawComittish ? '#' + rawComittish : ''
vars['/tree/comittish'] = vars.comittish ? '/' + vars.treepath + '/' + vars.comittish : ''
vars['/comittish'] = vars.comittish ? '/' + vars.comittish : ''
vars.comittish = vars.comittish || 'master'
var res = template
Object.keys(vars).forEach(function(K){
res = res.replace(new RegExp("[{]" + K + "[}]", "g"), vars[K])
Object.keys(vars).forEach(function (K) {
res = res.replace(new RegExp('[{]' + K + '[}]', 'g'), vars[K])
})

@@ -188,5 +191,5 @@ return res

GitHost.prototype.bugs = function() {
if (! this.bugstemplate) return
return this._fill(this.bugstemplate)
GitHost.prototype.bugs = function () {
var bugstemplate = this.bugstemplate || gitHostDefaults.bugstemplate
return this._fill(bugstemplate)
}

@@ -200,15 +203,29 @@

GitHost.prototype.git = function () {
if (! this.gittemplate) return
return this._fill(this.gittemplate)
var gittemplate = this.gittemplate || gitHostDefaults.gittemplate
return this._fill(gittemplate)
}
GitHost.prototype.shortcut = function () {
var shortcuttemplate = this.shortcuttemplate || gitHostDefaults.shortcuttemplate
return this._fill(shortcuttemplate)
}
GitHost.prototype.path = function () {
var pathtemplate = this.pathtemplate || gitHostDefaults.pathtemplate
return this._fill(pathtemplate)
}
GitHost.prototype.file = function (P) {
var filetemplate = this.filetemplate || gitHostDefaults.filetemplate
return this._fill(filetemplate, {
path: P.replace(/^[/]+/g, "")
path: P.replace(/^[/]+/g, '')
})
}
GitHost.prototype.getDefaultType = function () {
return this.default
}
GitHost.prototype.toString = function () {
return this[this.default||"sshurl"]()
return this[this.default || 'sshurl']() || this.sshurl()
}
{
"name": "hosted-git-info",
"version": "1.5.3",
"version": "1.6.0",
"description": "Provides metadata and conversions from repository urls for Github, Bitbucket and Gitlab",

@@ -23,7 +23,8 @@ "main": "index.js",

"scripts": {
"test": "tap test/*.js"
"test": "standard && tap test/*.js"
},
"devDependencies": {
"standard": "^3.3.2",
"tap": "^0.4.13"
}
}

@@ -78,2 +78,19 @@ # hosted-git-info

* info.getDefaultType()
Returns the default output type. The default output type is based on the
string you passed in to be parsed
* info.toString()
Uses the getDefaultType 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

@@ -80,0 +97,0 @@

@@ -1,9 +0,15 @@

"use strict"
var HostedGit = require("../index")
var test = require("tap").test
'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.end()
test('basic', function (t) {
t.is(HostedGit.fromUrl('https://google.com'), undefined, 'null on failure')
t.is(HostedGit.fromUrl('https://github.com/abc/def').getDefaultType(), 'https', 'match https urls')
t.is(HostedGit.fromUrl('ssh://git@github.com/abc/def').getDefaultType(), 'sshurl', 'match ssh urls')
t.is(HostedGit.fromUrl('git+ssh://git@github.com/abc/def').getDefaultType(), 'sshurl', 'match git+ssh urls')
t.is(HostedGit.fromUrl('git+https://github.com/abc/def').getDefaultType(), 'https', 'match git+https urls')
t.is(HostedGit.fromUrl('git@github.com:abc/def').getDefaultType(), 'sshurl', 'match ssh connect strings')
t.is(HostedGit.fromUrl('git://github.com/abc/def').getDefaultType(), 'git', 'match git urls')
t.is(HostedGit.fromUrl('github:abc/def').getDefaultType(), 'shortcut', 'match shortcuts')
t.end()
})

@@ -1,24 +0,23 @@

"use strict"
var HostedGit = require("../index")
var test = require("tap").test
'use strict'
var HostedGit = require('../index')
var test = require('tap').test
test("fromUrl(bitbucket url)", function (t) {
function verify(host, label, branch) {
test('fromUrl(bitbucket url)', function (t) {
function verify (host, label, branch) {
var hostinfo = HostedGit.fromUrl(host)
var hash = branch ? "#" + branch : ""
var hash = branch ? '#' + branch : ''
t.ok(hostinfo, label)
if (! hostinfo) return
t.is( hostinfo.https(), "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), "git+ssh://git@bitbucket.org/111/222.git" + hash, label + " -> stringify" )
t.is( hostinfo.file("C"), "https://bitbucket.org/111/222/raw/"+(branch||"master")+"/C", label + " -> file" )
if (!hostinfo) return
t.is(hostinfo.https(), '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')
}
require('./lib/standard-tests')(verify, "bitbucket.org", "bitbucket")
require('./lib/standard-tests')(verify, 'bitbucket.org', 'bitbucket')
t.end()
})

@@ -1,40 +0,38 @@

"use strict"
var HostedGit = require("../index")
var test = require("tap").test
'use strict'
var HostedGit = require('../index')
var test = require('tap').test
test("fromUrl(gist url)", function (t) {
function verify(host, label, branch) {
test('fromUrl(gist url)', function (t) {
function verify (host, label, branch) {
var hostinfo = HostedGit.fromUrl(host)
var hash = branch ? "#" + branch : ""
var hash = branch ? '#' + branch : ''
t.ok(hostinfo, label)
if (! hostinfo) return
t.is( hostinfo.https(), "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), "git+ssh://git@gist.github.com/222.git" + hash, label + " -> stringify" )
if (!hostinfo) return
t.is(hostinfo.https(), '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.file('C'), 'https://gist.githubusercontent.com/111/222/raw/' + (branch ? branch + '/' : '') + 'C', label + ' -> file')
}
}
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(), "https://gist.github.com/ef860c7z5e0de3179341.git", "git@hex -> https" )
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(), '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")
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")
require('./lib/standard-tests')(verify, 'gist.github.com', 'gist')
t.end()
})

@@ -1,42 +0,40 @@

"use strict"
var HostedGit = require("../index")
var test = require("tap").test
'use strict'
var HostedGit = require('../index')
var test = require('tap').test
test("fromUrl(github url)", function (t) {
function verify(host, label, branch) {
test('fromUrl(github url)', function (t) {
function verify (host, label, branch) {
var hostinfo = HostedGit.fromUrl(host)
var hash = branch ? "#" + branch : ""
var hash = branch ? '#' + branch : ''
t.ok(hostinfo, label)
if (! hostinfo) return
t.is( hostinfo.https(), "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), "git+ssh://git@github.com/111/222.git" + hash, label + " -> stringify" )
t.is( hostinfo.file("C"), "https://raw.githubusercontent.com/111/222/"+(branch||"master")+"/C", label + " -> file" )
if (!hostinfo) return
t.is(hostinfo.https(), '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')
}
// github shorturls
verify("111/222", "github-short")
verify("111/222#branch", "github-short#branch", "branch")
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('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")
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")
require('./lib/standard-tests')(verify, 'github.com', 'github')
t.end()
})

@@ -1,25 +0,23 @@

"use strict"
var HostedGit = require("../index")
var test = require("tap").test
'use strict'
var HostedGit = require('../index')
var test = require('tap').test
test("fromUrl(gitlab url)", function (t) {
function verify(host, label, branch) {
test('fromUrl(gitlab url)', function (t) {
function verify (host, label, branch) {
var hostinfo = HostedGit.fromUrl(host)
var hash = branch ? "#" + branch : ""
var hash = branch ? '#' + branch : ''
t.ok(hostinfo, label)
if (! hostinfo) return
t.is( hostinfo.https(), "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), "git+ssh://git@gitlab.com/111/222.git" + hash, label + " -> stringify" )
t.is( hostinfo.file("C"), "https://gitlab.com/111/222/raw/"+(branch||"master")+"/C", label + " -> file" )
if (!hostinfo) return
t.is(hostinfo.https(), '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')
}
require('./lib/standard-tests')(verify, "gitlab.com", "gitlab")
require('./lib/standard-tests')(verify, 'gitlab.com', 'gitlab')
t.end()
})

@@ -1,28 +0,27 @@

"use strict"
'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('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+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@' + 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("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")
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')
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc