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.3.0 to 1.4.0

test/gist.js

55

index.js

@@ -13,2 +13,3 @@ "use strict"

this.bugstemplate = gitHosts[type].bugstemplate
this.gittemplate = gitHosts[type].gittemplate
this.httpstemplate = gitHosts[type].httpstemplate

@@ -23,3 +24,4 @@ this.treepath = gitHosts[type].treepath

exports.fromUrl = function (giturl) {
var parsed = parseGitUrl(giturl)
if (giturl == null || giturl == "") return
var parsed = parseGitUrl(maybeGitHubShorthand(giturl) ? "github:" + giturl : giturl)
var matches = Object.keys(gitHosts).map(function(V) {

@@ -34,5 +36,9 @@ var gitHost = gitHosts[V]

if (! gitHost.protocols_re.test(parsed.protocol)) return
var matched = parsed.path.match(/^[/]([^/]+)[/]([^/]+?)(?:[.]git)?$/)
var matched = parsed.path.match(gitHost.pathmatch)
if (! matched) return
return new GitHost(V, decodeURIComponent(matched[1]), decodeURIComponent(matched[2]), comittish)
return new GitHost(
V,
matched[1]!=null && decodeURIComponent(matched[1]),
matched[2]!=null && decodeURIComponent(matched[2]),
comittish)
}).filter(function(V){ return V })

@@ -43,4 +49,17 @@ if (matches.length != 1) return

function maybeGitHubShorthand(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)
}
var parseGitUrl = function (giturl) {
var matched = giturl.match(/^([^@]+)@([^:]+):([^/]+[/][^/]+?)(?:[.]git)?(#.*)?$/)
if (typeof giturl != "string") giturl = "" + giturl
var matched = giturl.match(/^([^@]+)@([^:]+):[/]?((?:[^/]+[/])?[^/]+?)(?:[.]git)?(#.*)?$/)
if (! matched) return url.parse(giturl)

@@ -67,5 +86,7 @@ return {

"domain": "github.com",
"pathmatch": /^[/]([^/]+)[/]([^/]+?)(?:[.]git)?$/,
"treepath": "tree",
"filetemplate": "https://raw.githubusercontent.com/{user}/{project}/{comittish}/{path}",
"bugstemplate": "https://{domain}/{user}/{project}/issues"
"bugstemplate": "https://{domain}/{user}/{project}/issues",
"gittemplate": "git://{domain}/{user}/{project}.git{#comittish}"
},

@@ -75,2 +96,3 @@ bitbucket: {

"domain": "bitbucket.org",
"pathmatch": /^[/]([^/]+)[/]([^/]+?)(?:[.]git)?$/,
"treepath": "src"

@@ -81,6 +103,20 @@ },

"domain": "gitlab.com",
"pathmatch": /^[/]([^/]+)[/]([^/]+?)(?:[.]git)?$/,
"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": /^[/](?:([^/]+)[/])?(\d+)(?:[.]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}",
},
}

@@ -116,3 +152,3 @@

vars["/tree/comittish"] = vars.comittish ? "/"+vars.treepath+"/" + vars.comittish : "",
vars["/src/comittish"] = vars.comittish ? "/src/" + vars.comittish : "",
vars["/comittish"] = vars.comittish ? "/" + vars.comittish : ""
vars.comittish = vars.comittish || "master"

@@ -156,2 +192,7 @@ var res = template

GitHost.prototype.git = function () {
if (! this.gittemplate) return
return this._fill(this.gittemplate)
}
GitHost.prototype.file = function (P) {

@@ -158,0 +199,0 @@ var filetemplate = this.filetemplate || "https://{domain}/{user}/{project}/raw/{comittish}/{path}"

2

package.json
{
"name": "hosted-git-info",
"version": "1.3.0",
"version": "1.4.0",
"description": "Provides metadata and conversions from repository urls for Github, Bitbucket and Gitlab",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -24,3 +24,5 @@ # hosted-git-info

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`).
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`.

@@ -27,0 +29,0 @@ If it does match, the returned object has properties of:

@@ -11,9 +11,9 @@ "use strict"

if (! hostinfo) return
t.is( hostinfo.https().toLowerCase(), "https://bitbucket.org/a/b.git" + hash, label + " -> https" )
t.is( hostinfo.browse().toLowerCase(), "https://bitbucket.org/a/b" + (branch ? "/src/" + branch : ""), label + " -> browse" )
t.is( hostinfo.docs().toLowerCase(), "https://bitbucket.org/a/b" + (branch ? "/src/" + branch : "") + "#readme", label + " -> docs" )
t.is( hostinfo.ssh().toLowerCase(), "git@bitbucket.org:a/b.git" + hash, label + " -> ssh" )
t.is( hostinfo.sshurl().toLowerCase(), "git+ssh://git@bitbucket.org/a/b.git" + hash, label + " -> sshurl" )
t.is( (""+hostinfo).toLowerCase(), "git+ssh://git@bitbucket.org/a/b.git" + hash, label + " -> stringify" )
t.is( hostinfo.file("C").toLowerCase(), "https://bitbucket.org/a/b/raw/"+(branch||"master")+"/c", label + " -> file" )
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" )
}

@@ -20,0 +20,0 @@

@@ -12,16 +12,19 @@ "use strict"

if (! hostinfo) return
t.is( hostinfo.https().toLowerCase(), "https://github.com/a/b.git" + hash, label + " -> https" )
t.is( hostinfo.browse().toLowerCase(), "https://github.com/a/b" + (branch ? "/tree/" + branch : ""), label + " -> browse" )
t.is( hostinfo.bugs().toLowerCase(), "https://github.com/a/b/issues", label + " -> bugs" )
t.is( hostinfo.docs().toLowerCase(), "https://github.com/a/b" + (branch ? "/tree/" + branch : "") + "#readme", label + " -> docs" )
t.is( hostinfo.ssh().toLowerCase(), "git@github.com:a/b.git" + hash, label + " -> ssh" )
t.is( hostinfo.sshurl().toLowerCase(), "git+ssh://git@github.com/a/b.git" + hash, label + " -> sshurl" )
t.is( (""+hostinfo).toLowerCase(), "git+ssh://git@github.com/a/b.git" + hash, label + " -> stringify" )
t.is( hostinfo.file("C").toLowerCase(), "https://raw.githubusercontent.com/a/b/"+(branch||"master")+"/c", label + " -> file" )
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" )
}
verify("git://github.com/A/B", "git")
verify("git://github.com/A/B.git", "git.git")
verify("git://github.com/A/B#branch", "git#branch", "branch")
verify("git://github.com/A/B.git#branch", "git.git#branch", "branch")
verify("111/222", "github-short")
verify("111/222#branch", "github-short#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")

@@ -28,0 +31,0 @@ require('./lib/standard-tests')(verify, "github.com", "github")

@@ -12,9 +12,9 @@ "use strict"

if (! hostinfo) return
t.is( hostinfo.https().toLowerCase(), "https://gitlab.com/a/b.git" + hash, label + " -> https" )
t.is( hostinfo.browse().toLowerCase(), "https://gitlab.com/a/b" + (branch ? "/tree/" + branch : ""), label + " -> browse" )
t.is( hostinfo.docs().toLowerCase(), "https://gitlab.com/a/b" + (branch ? "/tree/" + branch : "") + "#readme", label + " -> docs" )
t.is( hostinfo.ssh().toLowerCase(), "git@gitlab.com:a/b.git" + hash, label + " -> ssh" )
t.is( hostinfo.sshurl().toLowerCase(), "git+ssh://git@gitlab.com/a/b.git" + hash, label + " -> sshurl" )
t.is( (""+hostinfo).toLowerCase(), "git+ssh://git@gitlab.com/a/b.git" + hash, label + " -> stringify" )
t.is( hostinfo.file("C").toLowerCase(), "https://gitlab.com/a/b/raw/"+(branch||"master")+"/c", label + " -> file" )
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" )
}

@@ -21,0 +21,0 @@

"use strict"
module.exports = function (verify, domain, shortname) {
verify("https://" + domain + "/A/B", "https")
verify("https://" + domain + "/A/B.git", "https.git")
verify("https://" + domain + "/A/B#branch", "https#branch", "branch")
verify("https://" + domain + "/A/B.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 + "/A/B", "git+https")
verify("git+https://" + domain + "/A/B.git", "git+https.git")
verify("git+https://" + domain + "/A/B#branch", "git+https#branch", "branch")
verify("git+https://" + domain + "/A/B.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 + ":A/B", "ssh")
verify("git@" + domain + ":A/B.git", "ssh.git")
verify("git@" + domain + ":A/B#branch", "ssh", "branch")
verify("git@" + domain + ":A/B.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 + "/A/B", "ssh url")
verify("git+ssh://git@" + domain + "/A/B.git", "ssh url.git")
verify("git+ssh://git@" + domain + "/A/B#branch", "ssh url#branch", "branch")
verify("git+ssh://git@" + domain + "/A/B.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 + ":A/B", "shortcut")
verify(shortname + ":A/B.git", "shortcut.git")
verify(shortname + ":A/B#branch", "shortcut#branch", "branch")
verify(shortname + ":A/B.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")
}
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