Files
shields/services/github/github-code-size.service.js
Caleb Cartwright fa608e29d3 refactor(github): convert some clasess to static fields (#5556)
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2020-09-20 20:17:22 +00:00

40 lines
918 B
JavaScript

'use strict'
const prettyBytes = require('pretty-bytes')
const { BaseGithubLanguage } = require('./github-languages-base')
const { documentation } = require('./github-helpers')
module.exports = 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) })
}
}