Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getSuccessStats (options) {
verify.unemptyString(options.name, 'missing name')
verify.unemptyString(options.from, 'missing from version')
verify.unemptyString(options.to, 'missing to version')
verify.webUrl(nextUpdateStatsUrl, 'missing next update stats server url')
var opts = {
uri: nextUpdateStatsUrl + '/package/' + options.name + '/' + options.from +
'/' + options.to,
method: 'GET',
json: options
}
var defer = Q.defer()
request(opts, function (err, response, stats) {
if (err || response.statusCode !== 200) {
if (response) {
if (response.statusCode !== 404) {
console.error('could not get success stats for', options.name)
console.error(opts)
}
function getSuccessStats (options) {
verify.unemptyString(options.name, 'missing name')
verify.unemptyString(options.from, 'missing from version')
verify.unemptyString(options.to, 'missing to version')
verify.webUrl(nextUpdateStatsUrl, 'missing next update stats server url')
var opts = {
uri: nextUpdateStatsUrl + '/package/' + options.name + '/' + options.from +
'/' + options.to,
method: 'GET',
json: options
}
var defer = Q.defer()
request(opts, function (err, response, stats) {
if (err || response.statusCode !== 200) {
if (response) {
if (response.statusCode !== 404) {
console.error('could not get success stats for', options.name)
function sendUpdateResult (options) {
verify.unemptyString(options.name, 'missing name')
verify.unemptyString(options.from, 'missing from version')
verify.unemptyString(options.to, 'missing to version')
if (options.success) {
options.success = !!options.success
}
verify.webUrl(nextUpdateStatsUrl, 'missing next update stats server url')
var sendOptions = {
uri: nextUpdateStatsUrl + '/update',
method: 'POST',
json: options
}
request(sendOptions, function ignoreResponse () {})
}
function sendUpdateResult (options) {
verify.unemptyString(options.name, 'missing name')
verify.unemptyString(options.from, 'missing from version')
verify.unemptyString(options.to, 'missing to version')
if (options.success) {
options.success = !!options.success
}
verify.webUrl(nextUpdateStatsUrl, 'missing next update stats server url')
var sendOptions = {
uri: nextUpdateStatsUrl + '/update',
method: 'POST',
json: options
}
request(sendOptions, function ignoreResponse () {})
}
function formatStats (options, stats) {
verify.object(stats, 'missing stats object')
verify.unemptyString(stats.name, 'missing name')
verify.unemptyString(stats.from, 'missing from version')
verify.unemptyString(stats.to, 'missing to version')
stats.success = +stats.success || 0
stats.failure = +stats.failure || 0
var total = stats.success + stats.failure
var probability = (total > 0 ? stats.success / total : 0)
var probabilityStr = colorProbability(probability, options)
return oneLine`
stats: ${stats.name} ${stats.from} -> ${stats.to}
success probability ${probabilityStr}
${stats.success} ${pluralize('success', stats.success)}
${stats.failure} ${pluralize('failure', stats.failure)}
`
}
function formatStats (options, stats) {
verify.object(stats, 'missing stats object')
verify.unemptyString(stats.name, 'missing name')
verify.unemptyString(stats.from, 'missing from version')
verify.unemptyString(stats.to, 'missing to version')
stats.success = +stats.success || 0
stats.failure = +stats.failure || 0
var total = stats.success + stats.failure
var probability = (total > 0 ? stats.success / total : 0)
var probabilityStr = colorProbability(probability, options)
return oneLine`
stats: ${stats.name} ${stats.from} -> ${stats.to}
success probability ${probabilityStr}
${stats.success} ${pluralize('success', stats.success)}
${stats.failure} ${pluralize('failure', stats.failure)}
`
}
function formatStats (options, stats) {
verify.object(stats, 'missing stats object')
verify.unemptyString(stats.name, 'missing name')
verify.unemptyString(stats.from, 'missing from version')
verify.unemptyString(stats.to, 'missing to version')
stats.success = +stats.success || 0
stats.failure = +stats.failure || 0
var total = stats.success + stats.failure
var probability = (total > 0 ? stats.success / total : 0)
var probabilityStr = colorProbability(probability, options)
return oneLine`
stats: ${stats.name} ${stats.from} -> ${stats.to}
success probability ${probabilityStr}
${stats.success} ${pluralize('success', stats.success)}
${stats.failure} ${pluralize('failure', stats.failure)}
`
}
function sendUpdateResult (options) {
verify.unemptyString(options.name, 'missing name')
verify.unemptyString(options.from, 'missing from version')
verify.unemptyString(options.to, 'missing to version')
if (options.success) {
options.success = !!options.success
}
verify.webUrl(nextUpdateStatsUrl, 'missing next update stats server url')
var sendOptions = {
uri: nextUpdateStatsUrl + '/update',
method: 'POST',
json: options
}
request(sendOptions, function ignoreResponse () {})
}