Files
shields/services/codefactor/codefactor-helpers.js
chris48s 504015c0ba migrate hapi/joi to joi (#5624)
* update joi + joi-extension-semver

* @hapi/joi --> joi

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2020-09-30 17:51:02 +00:00

35 lines
689 B
JavaScript

'use strict'
const Joi = require('joi')
// https://support.codefactor.io/i14-glossary
// https://github.com/badges/shields/issues/4269
const colorMap = {
'A+': 'brightgreen',
A: 'brightgreen',
'A-': 'green',
'B+': 'yellowgreen',
B: 'yellowgreen',
'B-': 'yellowgreen',
'C+': 'yellow',
C: 'yellow',
'C-': 'yellow',
'D+': 'orange',
D: 'orange',
'D-': 'orange',
F: 'red',
'-': 'lightgrey',
}
const isValidGrade = Joi.valid(...Object.keys(colorMap)).required()
function gradeColor(grade) {
const color = colorMap[grade]
if (color === undefined) {
throw Error(`Unknown grade: ${grade}`)
}
return color
}
module.exports = { isValidGrade, gradeColor }