Files
shields/services/codefactor/codefactor-grade.service.js
Caleb Cartwright b7dcf58bd6 convert some service classes to static props, run [codefactor codeship conda continuousphp] (#5515)
* refactor(codefactor): convert to static props

* refactor(codeship): convert to static props

* refactor(conda): convert to static props

* refactor(continuousphp): convert to static props

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

51 lines
1.2 KiB
JavaScript

'use strict'
const Joi = require('@hapi/joi')
const { BaseSvgScrapingService } = require('..')
const { isValidGrade, gradeColor } = require('./codefactor-helpers')
const schema = Joi.object({
message: isValidGrade,
}).required()
module.exports = class CodeFactorGrade extends BaseSvgScrapingService {
static category = 'analysis'
static route = {
base: 'codefactor/grade',
pattern: ':vcsType(github|bitbucket)/:user/:repo/:branch*',
}
static examples = [
{
title: 'CodeFactor Grade',
namedParams: {
vcsType: 'github',
user: 'pallets',
repo: 'flask',
branch: 'master',
},
staticPreview: this.render({ grade: 'B+' }),
},
]
static defaultBadgeData = { label: 'code quality' }
static render({ grade }) {
return {
message: grade,
color: gradeColor(grade),
}
}
async handle({ vcsType, user, repo, branch }) {
const { message } = await this._requestSvg({
schema,
url: `https://codefactor.io/repository/${vcsType}/${user}/${repo}/badge/${
branch || ''
}`,
errorMessages: { 404: 'repo or branch not found' },
})
return this.constructor.render({ grade: message })
}
}