Files
shields/services/github/github-watchers.service.js
Pierre-Yves Bigourdan 04254e5905 Ensure social category badges are rendered with social style and logo; affects [gitlab keybase lemmy modrinth thunderstore twitch] gist github reddit (#9859)
* Ensure social category badges are rendered with social style and logo

* Fix Twitch auth test
2023-12-31 14:08:55 +00:00

64 lines
1.5 KiB
JavaScript

import Joi from 'joi'
import { metric } from '../text-formatters.js'
import { nonNegativeInteger } from '../validators.js'
import { GithubAuthV3Service } from './github-auth-service.js'
import { documentation, httpErrorsFor } from './github-helpers.js'
const schema = Joi.object({
subscribers_count: nonNegativeInteger,
}).required()
export default class GithubWatchers extends GithubAuthV3Service {
static category = 'social'
static route = {
base: 'github/watchers',
pattern: ':user/:repo',
}
static examples = [
{
title: 'GitHub watchers',
namedParams: {
user: 'badges',
repo: 'shields',
},
// TODO: This is currently a literal, as `staticPreview` doesn't
// support `link`.
staticPreview: {
label: 'Watch',
message: '96',
style: 'social',
},
queryParams: { label: 'Watch' },
documentation,
},
]
static defaultBadgeData = {
label: 'watchers',
namedLogo: 'github',
}
static render({ watchers, user, repo }) {
return {
message: metric(watchers),
style: 'social',
color: 'blue',
link: [
`https://github.com/${user}/${repo}`,
`https://github.com/${user}/${repo}/watchers`,
],
}
}
async handle({ user, repo }) {
const { subscribers_count: watchers } = await this._requestJson({
url: `/repos/${user}/${repo}`,
schema,
httpErrors: httpErrorsFor(),
})
return this.constructor.render({ user, repo, watchers })
}
}