Files
shields/services/github/github-followers.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

46 lines
1.2 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({
followers: nonNegativeInteger,
}).required()
export default class GithubFollowers extends GithubAuthV3Service {
static category = 'social'
static route = { base: 'github/followers', pattern: ':user' }
static examples = [
{
title: 'GitHub followers',
namedParams: { user: 'espadrine' },
staticPreview: Object.assign(this.render({ followers: 150 }), {
label: 'Follow',
style: 'social',
}),
queryParams: { label: 'Follow' },
documentation,
},
]
static defaultBadgeData = { label: 'followers', namedLogo: 'github' }
static render({ followers }) {
return {
message: metric(followers),
style: 'social',
color: 'blue',
}
}
async handle({ user }) {
const { followers } = await this._requestJson({
url: `/users/${user}`,
schema,
httpErrors: httpErrorsFor('user not found'),
})
return this.constructor.render({ followers })
}
}