Files
shields/services/github/github-forks.service.js
dependabot-preview[bot] 636ed87057 Build(deps-dev): bump prettier from 2.2.1 to 2.3.0, run [ciibestpractices eclipsemarketplacedownloads gemdownloads githubdeployments githubtotaldiscussions githubforks githubhacktoberfest githubissuessearch githubpackagejson githubsponsors githubtag jenkinscoverage node npm nuget scoop teamcitybuild testspace] (#6482)
* Build(deps-dev): bump prettier from 2.2.1 to 2.3.0

Bumps [prettier](https://github.com/prettier/prettier) from 2.2.1 to 2.3.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.2.1...2.3.0)

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

* chore: prettier

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Caleb Cartwright <caleb.cartwright@outlook.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2021-05-15 08:49:20 +00:00

78 lines
1.9 KiB
JavaScript

'use strict'
const gql = require('graphql-tag')
const Joi = require('joi')
const { metric } = require('../text-formatters')
const { nonNegativeInteger } = require('../validators')
const { GithubAuthV4Service } = require('./github-auth-service')
const { documentation, transformErrors } = require('./github-helpers')
const schema = Joi.object({
data: Joi.object({
repository: Joi.object({
forkCount: nonNegativeInteger,
}).required(),
}).required(),
}).required()
module.exports = class GithubForks extends GithubAuthV4Service {
static category = 'social'
static route = { base: 'github/forks', pattern: ':user/:repo' }
static examples = [
{
title: 'GitHub forks',
namedParams: {
user: 'badges',
repo: 'shields',
},
// TODO: This is currently a literal, as `staticPreview` doesn't
// support `link`.
staticPreview: {
label: 'Fork',
message: '150',
style: 'social',
},
// staticPreview: {
// ...this.render({ user: 'badges', repo: 'shields', forkCount: 150 }),
// label: 'fork',
// style: 'social',
// },
queryParams: { label: 'Fork' },
documentation,
},
]
static defaultBadgeData = { label: 'forks', namedLogo: 'github' }
static render({ user, repo, forkCount }) {
return {
message: metric(forkCount),
color: 'blue',
link: [
`https://github.com/${user}/${repo}/fork`,
`https://github.com/${user}/${repo}/network`,
],
}
}
async handle({ user, repo }) {
const json = await this._requestGraphql({
query: gql`
query ($user: String!, $repo: String!) {
repository(owner: $user, name: $repo) {
forkCount
}
}
`,
variables: { user, repo },
schema,
transformErrors,
})
return this.constructor.render({
user,
repo,
forkCount: json.data.repository.forkCount,
})
}
}