summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/hosted-git-info/git-host.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/hosted-git-info/git-host.js')
-rw-r--r--deps/npm/node_modules/hosted-git-info/git-host.js84
1 files changed, 51 insertions, 33 deletions
diff --git a/deps/npm/node_modules/hosted-git-info/git-host.js b/deps/npm/node_modules/hosted-git-info/git-host.js
index ea31380a4e..4c6641bbf7 100644
--- a/deps/npm/node_modules/hosted-git-info/git-host.js
+++ b/deps/npm/node_modules/hosted-git-info/git-host.js
@@ -1,7 +1,8 @@
'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) {
+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) {
@@ -12,6 +13,7 @@ var GitHost = module.exports = function (type, user, auth, project, committish,
gitHostInfo.project = project
gitHostInfo.committish = committish
gitHostInfo.default = defaultRepresentation
+ gitHostInfo.opts = opts || {}
}
GitHost.prototype = {}
@@ -19,9 +21,10 @@ GitHost.prototype.hash = function () {
return this.committish ? '#' + this.committish : ''
}
-GitHost.prototype._fill = function (template, vars) {
+GitHost.prototype._fill = function (template, opts) {
if (!template) return
- if (!vars) vars = {}
+ 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]
@@ -32,65 +35,80 @@ GitHost.prototype._fill = function (template, vars) {
vars[key] = encodeURIComponent(vars[key])
})
vars['auth@'] = rawAuth ? rawAuth + '@' : ''
- vars['#committish'] = rawComittish ? '#' + rawComittish : ''
- vars['/tree/committish'] = vars.committish
- ? '/' + vars.treepath + '/' + vars.committish
- : ''
- vars['/committish'] = vars.committish ? '/' + vars.committish : ''
- vars.committish = vars.committish || 'master'
+ 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])
})
- return res
+ if (opts.noGitPlus) {
+ return res.replace(/^git[+]/, '')
+ } else {
+ return res
+ }
}
-GitHost.prototype.ssh = function () {
- return this._fill(this.sshtemplate)
+GitHost.prototype.ssh = function (opts) {
+ return this._fill(this.sshtemplate, opts)
}
-GitHost.prototype.sshurl = function () {
- return this._fill(this.sshurltemplate)
+GitHost.prototype.sshurl = function (opts) {
+ return this._fill(this.sshurltemplate, opts)
}
-GitHost.prototype.browse = function () {
- return this._fill(this.browsetemplate)
+GitHost.prototype.browse = function (opts) {
+ return this._fill(this.browsetemplate, opts)
}
-GitHost.prototype.docs = function () {
- return this._fill(this.docstemplate)
+GitHost.prototype.docs = function (opts) {
+ return this._fill(this.docstemplate, opts)
}
-GitHost.prototype.bugs = function () {
- return this._fill(this.bugstemplate)
+GitHost.prototype.bugs = function (opts) {
+ return this._fill(this.bugstemplate, opts)
}
-GitHost.prototype.https = function () {
- return this._fill(this.httpstemplate)
+GitHost.prototype.https = function (opts) {
+ return this._fill(this.httpstemplate, opts)
}
-GitHost.prototype.git = function () {
- return this._fill(this.gittemplate)
+GitHost.prototype.git = function (opts) {
+ return this._fill(this.gittemplate, opts)
}
-GitHost.prototype.shortcut = function () {
- return this._fill(this.shortcuttemplate)
+GitHost.prototype.shortcut = function (opts) {
+ return this._fill(this.shortcuttemplate, opts)
}
-GitHost.prototype.path = function () {
- return this._fill(this.pathtemplate)
+GitHost.prototype.path = function (opts) {
+ return this._fill(this.pathtemplate, opts)
}
-GitHost.prototype.file = function (P) {
- return this._fill(this.filetemplate, {
+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 () {
- return (this[this.default] || this.sshurl).call(this)
+GitHost.prototype.toString = function (opts) {
+ return (this[this.default] || this.sshurl).call(this, opts)
}