* 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>
69 lines
1.7 KiB
JavaScript
69 lines
1.7 KiB
JavaScript
import Joi from 'joi'
|
|
import { optionalUrl } from '../validators.js'
|
|
import { metric } from '../text-formatters.js'
|
|
import { documentation, httpErrorsFor } from './gitlab-helper.js'
|
|
import GitLabBase from './gitlab-base.js'
|
|
|
|
/*
|
|
We're expecting a response like { "Ruby": 67.13, "JavaScript": 19.66 }
|
|
The keys could be anything and {} is a valid response (e.g: for an empty project)
|
|
*/
|
|
const schema = Joi.object().pattern(/./, Joi.number().min(0).max(100))
|
|
|
|
const queryParamSchema = Joi.object({
|
|
gitlab_url: optionalUrl,
|
|
}).required()
|
|
|
|
export default class GitlabLanguageCount extends GitLabBase {
|
|
static category = 'analysis'
|
|
|
|
static route = {
|
|
base: 'gitlab/languages/count',
|
|
pattern: ':project+',
|
|
queryParamSchema,
|
|
}
|
|
|
|
static examples = [
|
|
{
|
|
title: 'GitLab language count',
|
|
namedParams: {
|
|
project: 'gitlab-org/gitlab',
|
|
},
|
|
queryParams: { gitlab_url: 'https://gitlab.com' },
|
|
staticPreview: {
|
|
label: 'languages',
|
|
message: '5',
|
|
},
|
|
documentation,
|
|
},
|
|
]
|
|
|
|
static defaultBadgeData = { label: 'languages' }
|
|
|
|
static render({ languagesCount }) {
|
|
return {
|
|
message: metric(languagesCount),
|
|
color: 'blue',
|
|
}
|
|
}
|
|
|
|
async fetch({ project, baseUrl }) {
|
|
// https://docs.gitlab.com/ee/api/projects.html#languages
|
|
return super.fetch({
|
|
schema,
|
|
url: `${baseUrl}/api/v4/projects/${encodeURIComponent(
|
|
project,
|
|
)}/languages`,
|
|
httpErrors: httpErrorsFor('project not found'),
|
|
})
|
|
}
|
|
|
|
async handle({ project }, { gitlab_url: baseUrl = 'https://gitlab.com' }) {
|
|
const data = await this.fetch({
|
|
project,
|
|
baseUrl,
|
|
})
|
|
return this.constructor.render({ languagesCount: Object.keys(data).length })
|
|
}
|
|
}
|