* 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>
65 lines
2.0 KiB
JavaScript
65 lines
2.0 KiB
JavaScript
import Joi from 'joi'
|
|
import { optionalUrl, nonNegativeInteger } from '../validators.js'
|
|
import { renderContributorBadge } from '../contributor-count.js'
|
|
import { documentation, httpErrorsFor } from './gitlab-helper.js'
|
|
import GitLabBase from './gitlab-base.js'
|
|
|
|
const schema = Joi.object({ 'x-total': nonNegativeInteger }).required()
|
|
|
|
const queryParamSchema = Joi.object({
|
|
gitlab_url: optionalUrl,
|
|
}).required()
|
|
|
|
export default class GitlabContributors extends GitLabBase {
|
|
static category = 'activity'
|
|
static route = {
|
|
base: 'gitlab/contributors',
|
|
pattern: ':project+',
|
|
queryParamSchema,
|
|
}
|
|
|
|
static examples = [
|
|
{
|
|
title: 'GitLab contributors',
|
|
namedParams: {
|
|
project: 'gitlab-org/gitlab',
|
|
},
|
|
staticPreview: this.render({ contributorCount: 418 }),
|
|
documentation,
|
|
},
|
|
{
|
|
title: 'GitLab (self-managed) contributors',
|
|
queryParams: { gitlab_url: 'https://jihulab.com' },
|
|
namedParams: {
|
|
project: 'gitlab-cn/gitlab',
|
|
},
|
|
staticPreview: this.render({ contributorCount: 415 }),
|
|
documentation,
|
|
},
|
|
]
|
|
|
|
static defaultBadgeData = { label: 'contributors' }
|
|
|
|
static render({ contributorCount }) {
|
|
return renderContributorBadge({ contributorCount })
|
|
}
|
|
|
|
async handle({ project }, { gitlab_url: baseUrl = 'https://gitlab.com' }) {
|
|
// https://docs.gitlab.com/ee/api/repositories.html#contributors
|
|
const { res } = await this._request(
|
|
this.authHelper.withBearerAuthHeader({
|
|
url: `${baseUrl}/api/v4/projects/${encodeURIComponent(
|
|
project,
|
|
)}/repository/contributors`,
|
|
options: { searchParams: { page: '1', per_page: '1' } },
|
|
httpErrors: httpErrorsFor('project not found'),
|
|
}),
|
|
)
|
|
const data = this.constructor._validate(res.headers, schema)
|
|
// The total number of contributors is in the `x-total` field in the headers.
|
|
// https://docs.gitlab.com/ee/api/index.html#other-pagination-headers
|
|
const contributorCount = data['x-total']
|
|
return this.constructor.render({ contributorCount })
|
|
}
|
|
}
|