Files
shields/services/puppetforge/puppetforge-module-feedback.service.js
dependabot-preview[bot] 478d14300c Build(deps-dev): bump eslint-plugin-import from 2.20.1 to 2.20.2 (#4859)
* Build(deps-dev): bump eslint-plugin-import from 2.20.1 to 2.20.2

Bumps [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) from 2.20.1 to 2.20.2.
- [Release notes](https://github.com/benmosher/eslint-plugin-import/releases)
- [Changelog](https://github.com/benmosher/eslint-plugin-import/blob/master/CHANGELOG.md)
- [Commits](https://github.com/benmosher/eslint-plugin-import/compare/v2.20.1...v2.20.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Fixes

* refactor: combine imports

* refactor: combine imports

* refactor: combine imports

* refactor: update import ordering

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
Co-authored-by: Paul Melnikow <email@paulmelnikow.com>
Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
Co-authored-by: Caleb Cartwright <caleb.cartwright@outlook.com>
2020-04-16 18:39:13 -05:00

53 lines
1.2 KiB
JavaScript

'use strict'
const {
coveragePercentage: coveragePercentageColor,
} = require('../color-formatters')
const { NotFound } = require('..')
const { BasePuppetForgeModulesService } = require('./puppetforge-base')
module.exports = class PuppetforgeModuleFeedback extends BasePuppetForgeModulesService {
static get category() {
return 'rating'
}
static get route() {
return {
base: 'puppetforge/f',
pattern: ':user/:moduleName',
}
}
static get examples() {
return [
{
title: 'Puppet Forge feedback score',
namedParams: {
user: 'camptocamp',
moduleName: 'openssl',
},
staticPreview: this.render({ score: 61 }),
},
]
}
static get defaultBadgeData() {
return { label: 'score' }
}
static render({ score }) {
return {
message: `${score}%`,
color: coveragePercentageColor(score),
}
}
async handle({ user, moduleName }) {
const data = await this.fetch({ user, moduleName })
if (data.feedback_score == null) {
throw new NotFound({ prettyMessage: 'unknown' })
}
return this.constructor.render({ score: data.feedback_score })
}
}