Files
shields/services/conda/conda-downloads.service.js
chris48s 65dba94fa8 Stop calling variables "which"; affects [chocolatey codeclimate conda crates debug gem github mozillaobservatory nuget powershellgallery pub resharper vaadindirectory] (#3495)
* which --> variant

* which --> alias

* which --> format

* improve param names in codeclimate

* improve param names in github-issue-detail

* update github-issue-detail unit tests
2019-05-28 23:00:12 +01:00

47 lines
1.1 KiB
JavaScript

'use strict'
const { metric } = require('../text-formatters')
const { downloadCount } = require('../color-formatters')
const BaseCondaService = require('./conda-base')
module.exports = class CondaDownloads extends BaseCondaService {
static get category() {
return 'downloads'
}
static get route() {
return {
base: 'conda',
pattern: ':variant(d|dn)/:channel/:pkg',
}
}
static get examples() {
return [
{
title: 'Conda',
namedParams: { channel: 'conda-forge', package: 'python' },
pattern: 'dn/:channel/:package',
staticPreview: this.render({ variant: 'dn', downloads: 5000000 }),
},
]
}
static render({ variant, downloads }) {
return {
label: variant === 'dn' ? 'downloads' : 'conda|downloads',
message: metric(downloads),
color: downloadCount(downloads),
}
}
async handle({ variant, channel, pkg }) {
const json = await this.fetch({ channel, pkg })
const downloads = json.files.reduce(
(total, file) => total + file.ndownloads,
0
)
return this.constructor.render({ variant, downloads })
}
}