Files
shields/services/github/github-code-size.service.js
chris48s 3512c89054 migrate examples to openApi part 12; affects [GitHub Gist] (#9500)
* migrate some services from examples to openApi

* improve and de-dupe service titles

* improve description
2023-11-13 14:30:26 +00:00

46 lines
1.1 KiB
JavaScript

import prettyBytes from 'pretty-bytes'
import { pathParams } from '../index.js'
import { BaseGithubLanguage } from './github-languages-base.js'
import { documentation } from './github-helpers.js'
export default class GithubCodeSize extends BaseGithubLanguage {
static category = 'size'
static route = {
base: 'github/languages/code-size',
pattern: ':user/:repo',
}
static openApi = {
'/github/languages/code-size/{user}/{repo}': {
get: {
summary: 'GitHub code size in bytes',
description: documentation,
parameters: pathParams(
{
name: 'user',
example: 'badges',
},
{
name: 'repo',
example: 'shields',
},
),
},
},
}
static defaultBadgeData = { label: 'code size' }
static render({ size }) {
return {
message: prettyBytes(size),
color: 'blue',
}
}
async handle({ user, repo }) {
const data = await this.fetch({ user, repo })
return this.constructor.render({ size: this.getTotalSize(data) })
}
}