forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-top-language.service.js
More file actions
54 lines (47 loc) · 1.25 KB
/
Copy pathgithub-top-language.service.js
File metadata and controls
54 lines (47 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict'
const { BaseGithubLanguage } = require('./github-languages-base')
const { documentation } = require('./github-helpers')
module.exports = class GithubTopLanguage extends BaseGithubLanguage {
static category = 'analysis'
static route = {
base: 'github/languages/top',
pattern: ':user/:repo',
}
static examples = [
{
title: 'GitHub top language',
namedParams: {
user: 'badges',
repo: 'shields',
},
staticPreview: this.render({
language: 'javascript',
languageSize: 99.5,
totalSize: 100,
}),
documentation,
},
]
static defaultBadgeData = {
label: 'language',
}
static render({ language, languageSize, totalSize }) {
const message =
totalSize === 0
? 'none'
: `${((languageSize / totalSize) * 100).toFixed(1)}%`
return { label: language.toLowerCase(), message, color: 'blue' }
}
async handle({ user, repo }) {
const data = await this.fetch({ user, repo })
const language = Object.keys(data).reduce(
(a, b) => (data[a] > data[b] ? a : b),
'language'
)
return this.constructor.render({
language,
languageSize: data[language],
totalSize: this.getTotalSize(data),
})
}
}