Files
shields/services/github/github-code-size.service.js
2021-07-09 12:53:55 +01:00

38 lines
893 B
JavaScript

import prettyBytes from 'pretty-bytes'
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 examples = [
{
title: 'GitHub code size in bytes',
namedParams: {
user: 'badges',
repo: 'shields',
},
staticPreview: this.render({ size: 1625000 }),
documentation,
},
]
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) })
}
}