Files
shields/services/codacy/codacy-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

76 lines
1.7 KiB
JavaScript

'use strict'
const Joi = require('@hapi/joi')
const { BaseSvgScrapingService } = require('..')
const { codacyGrade } = require('./codacy-helpers')
const schema = Joi.object({ message: codacyGrade }).required()
module.exports = class CodacyGrade extends BaseSvgScrapingService {
static get category() {
return 'analysis'
}
static get route() {
return {
base: 'codacy/grade',
pattern: ':projectId/:branch*',
}
}
static get examples() {
return [
{
title: 'Codacy grade',
pattern: ':projectId',
namedParams: { projectId: 'e27821fb6289410b8f58338c7e0bc686' },
staticPreview: this.render({ grade: 'A' }),
},
{
title: 'Codacy branch grade',
pattern: ':projectId/:branch',
namedParams: {
projectId: 'e27821fb6289410b8f58338c7e0bc686',
branch: 'master',
},
staticPreview: this.render({ grade: 'A' }),
},
]
}
static get defaultBadgeData() {
return {
label: 'code quality',
}
}
static render({ grade }) {
const color = {
A: 'brightgreen',
B: 'green',
C: 'yellowgreen',
D: 'yellow',
E: 'orange',
F: 'red',
}[grade]
return {
message: grade,
color,
}
}
async handle({ projectId, branch }) {
const { message: grade } = await this._requestSvg({
schema,
url: `https://api.codacy.com/project/badge/grade/${encodeURIComponent(
projectId
)}`,
options: { qs: { branch } },
errorMessages: { 404: 'project or branch not found' },
valueMatcher: /visibility="hidden">([^<>]+)<\/text>/,
})
return this.constructor.render({ grade })
}
}