Files
shields/services/codacy/codacy-grade.service.js
dependabot[bot] b9d96755ec chore(deps-dev): bump prettier from 2.8.8 to 3.0.0 (#9357)
* chore(deps-dev): bump prettier from 2.8.8 to 3.0.0

Bumps [prettier](https://github.com/prettier/prettier) from 2.8.8 to 3.0.0.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.8.8...3.0.0)

---
updated-dependencies:
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* reformat all the things (prettier 3)

* update tests to await calls to prettier.format()

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: chris48s <git@chris-shaw.dev>
2023-07-10 09:27:51 +00:00

60 lines
1.5 KiB
JavaScript

import Joi from 'joi'
import { BaseSvgScrapingService } from '../index.js'
import { codacyGrade } from './codacy-helpers.js'
const schema = Joi.object({ message: codacyGrade }).required()
export default class CodacyGrade extends BaseSvgScrapingService {
static category = 'analysis'
static route = { base: 'codacy/grade', pattern: ':projectId/:branch*' }
static examples = [
{
title: 'Codacy grade',
pattern: ':projectId',
namedParams: { projectId: '0cb32ce695b743d68257021455330c66' },
staticPreview: this.render({ grade: 'A' }),
},
{
title: 'Codacy branch grade',
pattern: ':projectId/:branch',
namedParams: {
projectId: '0cb32ce695b743d68257021455330c66',
branch: 'master',
},
staticPreview: this.render({ grade: 'A' }),
},
]
static defaultBadgeData = { 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: { searchParams: { branch } },
httpErrors: { 404: 'project or branch not found' },
valueMatcher: /visibility="hidden">([^<>]+)<\/text>/,
})
return this.constructor.render({ grade })
}
}