* 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>
161 lines
3.9 KiB
JavaScript
161 lines
3.9 KiB
JavaScript
'use strict'
|
|
|
|
const Joi = require('@hapi/joi')
|
|
const { colorScale } = require('../color-formatters')
|
|
const { NotFound } = require('..')
|
|
const ScrutinizerBase = require('./scrutinizer-base')
|
|
|
|
const schema = Joi.object({
|
|
default_branch: Joi.string().required(),
|
|
applications: Joi.object()
|
|
.pattern(
|
|
/^/,
|
|
Joi.object({
|
|
index: Joi.object({
|
|
_embedded: Joi.object({
|
|
project: Joi.object({
|
|
metric_values: Joi.object({
|
|
'scrutinizer.test_coverage': Joi.number().positive(),
|
|
}).required(),
|
|
}).required(),
|
|
}).required(),
|
|
}),
|
|
})
|
|
)
|
|
.required(),
|
|
}).required()
|
|
|
|
// https://scrutinizer-ci.com/g/filp/whoops/code-structure/master/code-coverage
|
|
// < 40% - red
|
|
// 40-60% (inclusive) - yellow
|
|
// > 60% brightgreen
|
|
const scale = colorScale([40, 61], ['red', 'yellow', 'brightgreen'])
|
|
|
|
class ScrutinizerCoverageBase extends ScrutinizerBase {
|
|
static get category() {
|
|
return 'coverage'
|
|
}
|
|
|
|
static get defaultBadgeData() {
|
|
return {
|
|
label: 'coverage',
|
|
}
|
|
}
|
|
|
|
static render({ coverage }) {
|
|
return {
|
|
message: `${coverage.toFixed(0)}%`,
|
|
color: scale(coverage),
|
|
}
|
|
}
|
|
|
|
transform({ json, branch }) {
|
|
const { value: rawCoverage } = this.transformBranchInfoMetricValue({
|
|
json,
|
|
branch,
|
|
metric: 'scrutinizer.test_coverage',
|
|
})
|
|
|
|
if (!rawCoverage) {
|
|
throw new NotFound({ prettyMessage: 'coverage not found' })
|
|
}
|
|
|
|
return { coverage: rawCoverage * 100 }
|
|
}
|
|
|
|
async makeBadge({ vcs, slug, branch }) {
|
|
const json = await this.fetch({ schema, vcs, slug })
|
|
const { coverage } = this.transform({ json, branch })
|
|
return this.constructor.render({ coverage })
|
|
}
|
|
}
|
|
|
|
class ScrutinizerCoverage extends ScrutinizerCoverageBase {
|
|
static get route() {
|
|
return {
|
|
base: 'scrutinizer/coverage',
|
|
pattern: ':vcs(g|b)/:user/:repo/:branch*',
|
|
}
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'Scrutinizer coverage (GitHub/BitBucket)',
|
|
pattern: ':vcs(g|b)/:user/:repo/:branch?',
|
|
namedParams: {
|
|
vcs: 'g',
|
|
user: 'filp',
|
|
repo: 'whoops',
|
|
branch: 'master',
|
|
},
|
|
staticPreview: this.render({ coverage: 86 }),
|
|
},
|
|
]
|
|
}
|
|
|
|
async handle({ vcs, user, repo, branch }) {
|
|
return this.makeBadge({
|
|
vcs,
|
|
slug: `${user}/${repo}`,
|
|
branch,
|
|
})
|
|
}
|
|
}
|
|
|
|
class ScrutinizerCoverageGitLab extends ScrutinizerCoverageBase {
|
|
static get route() {
|
|
return {
|
|
base: 'scrutinizer/coverage/gl',
|
|
pattern: ':instance/:user/:repo/:branch*',
|
|
}
|
|
}
|
|
|
|
static get examples() {
|
|
// There are no known anonymous accessible Scrutinizer reports available for GitLab repos.
|
|
// The example used is valid, but the project will not be accessible if Shields users try to use it.
|
|
// https://gitlab.propertywindow.nl/propertywindow/client
|
|
// https://scrutinizer-ci.com/gl/propertywindow/propertywindow/client/badges/quality-score.png?b=master&s=dfae6992a48184cc2333b4c349cec0447f0d67c2
|
|
return [
|
|
{
|
|
title: 'Scrutinizer coverage (GitLab)',
|
|
pattern: ':instance/:user/:repo/:branch?',
|
|
namedParams: {
|
|
instance: 'propertywindow',
|
|
user: 'propertywindow',
|
|
repo: 'client',
|
|
branch: 'master',
|
|
},
|
|
staticPreview: this.render({ coverage: 94 }),
|
|
},
|
|
]
|
|
}
|
|
|
|
async handle({ instance, user, repo, branch }) {
|
|
return this.makeBadge({
|
|
vcs: 'gl',
|
|
slug: `${instance}/${user}/${repo}`,
|
|
branch,
|
|
})
|
|
}
|
|
}
|
|
|
|
class ScrutinizerCoveragePlainGit extends ScrutinizerCoverageBase {
|
|
static get route() {
|
|
return {
|
|
base: 'scrutinizer/coverage/gp',
|
|
pattern: ':slug/:branch*',
|
|
}
|
|
}
|
|
|
|
async handle({ slug, branch }) {
|
|
return this.makeBadge({ vcs: 'gp', slug, branch })
|
|
}
|
|
}
|
|
|
|
module.exports = [
|
|
ScrutinizerCoverage,
|
|
ScrutinizerCoverageGitLab,
|
|
ScrutinizerCoveragePlainGit,
|
|
]
|