node/deps/npm/lib/bugs.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

module.exports = bugs
bugs.usage = "npm bugs <pkgname>"
2012-06-11 12:29:47 +08:00
var exec = require("./utils/exec.js")
, npm = require("./npm.js")
, registry = npm.registry
, log = require("npmlog")
2012-09-25 23:28:55 +08:00
, opener = require("opener")
2012-06-11 12:29:47 +08:00
bugs.completion = function (opts, cb) {
if (opts.conf.argv.remain.length > 2) return cb()
2012-06-11 12:29:47 +08:00
registry.get("/-/short", 60000, function (er, list) {
return cb(null, list || [])
})
}
function bugs (args, cb) {
if (!args.length) return cb(bugs.usage)
var n = args[0].split("@").shift()
2012-06-11 12:29:47 +08:00
registry.get(n + "/latest", 3600, function (er, d) {
if (er) return cb(er)
var bugs = d.bugs
, repo = d.repository || d.repositories
2012-09-25 23:28:55 +08:00
, url
if (bugs) {
2012-09-25 23:28:55 +08:00
url = (typeof bugs === "string") ? bugs : bugs.url
} else if (repo) {
if (Array.isArray(repo)) repo = repo.shift()
if (repo.hasOwnProperty("url")) repo = repo.url
2012-06-11 12:29:47 +08:00
log.verbose("repository", repo)
if (repo && repo.match(/^(https?:\/\/|git(:\/\/|@))github.com/)) {
2012-09-25 23:28:55 +08:00
url = repo.replace(/^git(@|:\/\/)/, "https://")
.replace(/^https?:\/\/github.com:/, "https://github.com/")
.replace(/\.git$/, '')+"/issues"
}
}
2012-09-25 23:28:55 +08:00
if (!url) {
url = "https://npmjs.org/package/" + d.name
}
opener(url, { command: npm.config.get("browser") }, cb)
})
}