Files
shields/services/codefactor/codefactor-grade.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

61 lines
1.3 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 get category() {
return 'analysis'
}
static get route() {
return {
base: 'codefactor/grade',
pattern: ':vcsType(github|bitbucket)/:user/:repo/:branch*',
}
}
static get examples() {
return [
{
title: 'CodeFactor Grade',
namedParams: {
vcsType: 'github',
user: 'pallets',
repo: 'flask',
branch: 'master',
},
staticPreview: this.render({ grade: 'B+' }),
},
]
}
static get defaultBadgeData() {
return {
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 })
}
}