Add option plugin_languages_details (#87)

This commit is contained in:
Simon Lecoq
2021-01-31 12:29:50 +01:00
committed by GitHub
parent 5e57107278
commit bf1453c776
8 changed files with 91 additions and 18 deletions

View File

@@ -26,4 +26,5 @@ It is also possible to use a predefined set of colors from [colorsets.json](colo
plugin_languages_ignored: html, css # List of languages to ignore
plugin_languages_skipped: my-test-repo # List of repositories to skip
plugin_languages_colors: "0:orange, javascript:#ff0000, ..." # Make most used languages orange and JavaScript red
plugin_languages_details: bytes-size, percentage # Additionally display total bytes size and percentage
```

View File

@@ -7,7 +7,7 @@
return null
//Load inputs
let {ignored, skipped, colors} = imports.metadata.plugins.languages.inputs({data, account, q})
let {ignored, skipped, colors, details} = imports.metadata.plugins.languages.inputs({data, account, q})
//Custom colors
const colorsets = JSON.parse(`${await imports.fs.readFile(`${imports.__module(import.meta.url)}/colorsets.json`)}`)
@@ -18,7 +18,7 @@
//Iterate through user's repositories and retrieve languages data
console.debug(`metrics/compute/${login}/plugins > languages > processing ${data.user.repositories.nodes.length} repositories`)
const languages = {colors:{}, total:0, stats:{}}
const languages = {details, colors:{}, total:0, stats:{}}
for (const repository of data.user.repositories.nodes) {
//Skip repository if asked
if (skipped.includes(repository.name.toLocaleLowerCase())) {
@@ -41,9 +41,10 @@
//Compute languages stats
console.debug(`metrics/compute/${login}/plugins > languages > computing stats`)
Object.keys(languages.stats).map(name => languages.stats[name] /= languages.total)
languages.favorites = Object.entries(languages.stats).sort(([an, a], [bn, b]) => b - a).slice(0, 8).map(([name, value]) => ({name, value, color:languages.colors[name], x:0}))
languages.favorites = Object.entries(languages.stats).sort(([an, a], [bn, b]) => b - a).slice(0, 8).map(([name, value]) => ({name, value, size:value, color:languages.colors[name], x:0}))
const visible = {total:Object.values(languages.favorites).map(({size}) => size).reduce((a, b) => a + b, 0)}
for (let i = 0; i < languages.favorites.length; i++) {
languages.favorites[i].value /= visible.total
languages.favorites[i].x = (languages.favorites[i-1]?.x ?? 0) + (languages.favorites[i-1]?.value ?? 0)
if ((colors[i])&&(!colors[languages.favorites[i].name.toLocaleLowerCase()]))
languages.favorites[i].color = colors[i]

View File

@@ -26,7 +26,7 @@ inputs:
format: comma-separated
default: ""
# Overrides
# Overrides default languages colors
# Use `${n}:${color}` to change the color of the n-th most used language (e.g. "0:red" to make your most used language red)
# Use `${language}:${color}` to change the color of named language (e.g. "javascript:red" to make JavaScript language red, language case is ignored)
# Use a value from `colorsets.json` to use a predefined set of colors
@@ -38,3 +38,13 @@ inputs:
- comma-separated
- /((?<index>[0-9])|(?<language>[-+a-z0-9#])):(?<color>#?[-a-z0-9]+)/
default: github
# Languages additional details
plugin_languages_details:
description:
type: array
format: comma-separated
values:
- bytes-size # Languages total size written in bytes
- percentage # Languages proportions in %
default: ""