Files
shields/services/github/github-all-contributors.service.js
Joe Izzard a17bb10662 Implement All Contributors Badge, run [GitHubAllContributors] (#5163)
* feat: added all-contributors badge and test

* Update services/github/github-all-contributors.service.js

Updated to schema to ensure the array always exists

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>

* fix: added branch to parameters

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
2020-06-03 22:44:49 -05:00

61 lines
1.4 KiB
JavaScript

'use strict'
const Joi = require('@hapi/joi')
const { renderContributorBadge } = require('../contributor-count')
const { ConditionalGithubAuthV3Service } = require('./github-auth-service')
const { fetchJsonFromRepo } = require('./github-common-fetch')
const { documentation } = require('./github-helpers')
const schema = Joi.object({
contributors: Joi.array().required(),
}).required()
module.exports = class GithubAllContributorsService extends ConditionalGithubAuthV3Service {
static get category() {
return 'activity'
}
static get route() {
return {
base: 'github/all-contributors',
pattern: ':user/:repo/:branch*',
}
}
static get examples() {
return [
{
title: 'Github All Contributors',
namedParams: {
repo: 'all-contributors',
user: 'all-contributors',
branch: 'master',
},
staticPreview: this.render({ contributorCount: 66 }),
documentation,
},
]
}
static get defaultBadgeData() {
return { label: 'all contributors' }
}
static render({ contributorCount }) {
return renderContributorBadge({ contributorCount })
}
async handle({ user, repo, branch }) {
const { contributors } = await fetchJsonFromRepo(this, {
schema,
user,
repo,
branch,
filename: '.all-contributorsrc',
})
const contributorCount = contributors.length
return this.constructor.render({ contributorCount })
}
}