1
0
mirror of https://github.com/badges/shields.git synced 2025-07-07 07:01:09 +03:00

tidy up [GitHubGist] routes (#8510)

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
chris48s
2022-11-04 19:43:14 +00:00
committed by GitHub
parent e223f45bce
commit c8a0a8660e
8 changed files with 61 additions and 13 deletions

View File

@ -0,0 +1,47 @@
import Joi from 'joi'
import { formatDate } from '../../text-formatters.js'
import { age as ageColor } from '../../color-formatters.js'
import { GithubAuthV3Service } from '../github-auth-service.js'
import { documentation, errorMessagesFor } from '../github-helpers.js'
const schema = Joi.object({
updated_at: Joi.string().required(),
}).required()
export default class GithubGistLastCommit extends GithubAuthV3Service {
static category = 'activity'
static route = { base: 'github/gist/last-commit', pattern: ':gistId' }
static examples = [
{
title: 'GitHub Gist last commit',
namedParams: {
gistId: '8710649',
},
staticPreview: this.render({ commitDate: '2022-07-29T20:01:41Z' }),
keywords: ['latest'],
documentation,
},
]
static defaultBadgeData = { label: 'last commit' }
static render({ commitDate }) {
return {
message: formatDate(commitDate),
color: ageColor(Date.parse(commitDate)),
}
}
async fetch({ gistId }) {
return this._requestJson({
url: `/gists/${gistId}`,
schema,
errorMessages: errorMessagesFor('gist not found'),
})
}
async handle({ gistId }) {
const { updated_at: commitDate } = await this.fetch({ gistId })
return this.constructor.render({ commitDate })
}
}