The great refactor (#82)
This commit is contained in:
29
source/plugins/languages/README.md
Normal file
29
source/plugins/languages/README.md
Normal file
@@ -0,0 +1,29 @@
|
||||
### 🈷️ Most used languages <sup>🚧 <code>plugin_languages_colors</code> on <code>@master</code></sup>
|
||||
|
||||
The *languages* plugin displays which programming languages you use the most across all your repositories.
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.languages.svg">
|
||||
<img width="900" height="1" alt="">
|
||||
</td>
|
||||
</table>
|
||||
|
||||
It is possible to use custom colors for languages instead of those provided by GitHub by using `plugin_languages_colors` option.
|
||||
You can specify either an index with a color, or a language name (case insensitive) with a color.
|
||||
Colors can be either in hexadecimal format or a [named color](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value).
|
||||
It is also possible to use a predefined set of colors from [colorsets.json](colorsets.json)
|
||||
|
||||
#### ℹ️ Examples workflows
|
||||
|
||||
[➡️ Available options for this plugin](metadata.yml)
|
||||
|
||||
```yaml
|
||||
- uses: lowlighter/metrics@latest
|
||||
with:
|
||||
# ... other options
|
||||
plugin_languages: yes
|
||||
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
|
||||
```
|
||||
@@ -1,22 +1,21 @@
|
||||
//Setup
|
||||
export default async function ({login, data, imports, q}, {enabled = false} = {}) {
|
||||
export default async function ({login, data, imports, q, account}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.languages))
|
||||
return null
|
||||
//Parameters override
|
||||
let {"languages.ignored":ignored = "", "languages.skipped":skipped = "", "languages.colors":colors = ""} = q
|
||||
//Ignored languages
|
||||
ignored = decodeURIComponent(ignored).split(",").map(x => x.trim().toLocaleLowerCase()).filter(x => x)
|
||||
//Skipped repositories
|
||||
skipped = decodeURIComponent(skipped).split(",").map(x => x.trim().toLocaleLowerCase()).filter(x => x)
|
||||
//Custom colors
|
||||
const colorsets = JSON.parse(`${await imports.fs.readFile(`${imports.__module(import.meta.url)}/colorsets.json`)}`)
|
||||
if (`${colors}` in colorsets)
|
||||
colors = colorsets[`${colors}`]
|
||||
colors = Object.fromEntries(decodeURIComponent(colors).split(",").map(x => x.trim().toLocaleLowerCase()).filter(x => x).map(x => x.split(":").map(x => x.trim())))
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > custom colors ${JSON.stringify(colors)}`)
|
||||
|
||||
//Load inputs
|
||||
let {ignored, skipped, colors} = 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`)}`)
|
||||
if (`${colors}` in colorsets)
|
||||
colors = colorsets[`${colors}`]
|
||||
colors = Object.fromEntries(decodeURIComponent(colors).split(",").map(x => x.trim().toLocaleLowerCase()).filter(x => x).map(x => x.split(":").map(x => x.trim())))
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > custom colors ${JSON.stringify(colors)}`)
|
||||
|
||||
//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:{}}
|
||||
@@ -39,6 +38,7 @@
|
||||
languages.total += size
|
||||
}
|
||||
}
|
||||
|
||||
//Compute languages stats
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > computing stats`)
|
||||
Object.keys(languages.stats).map(name => languages.stats[name] /= languages.total)
|
||||
@@ -48,6 +48,7 @@
|
||||
if ((colors[i])&&(!colors[languages.favorites[i].name.toLocaleLowerCase()]))
|
||||
languages.favorites[i].color = colors[i]
|
||||
}
|
||||
|
||||
//Results
|
||||
return languages
|
||||
}
|
||||
|
||||
40
source/plugins/languages/metadata.yml
Normal file
40
source/plugins/languages/metadata.yml
Normal file
@@ -0,0 +1,40 @@
|
||||
name: "🈷️ Most used languages"
|
||||
cost: 0 API request
|
||||
supports:
|
||||
- user
|
||||
- organization
|
||||
- repository
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_languages:
|
||||
description: Display most used languages metrics
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
# List of languages that will be ignored
|
||||
plugin_languages_ignored:
|
||||
description: Languages to ignore
|
||||
type: array
|
||||
format: comma-separated
|
||||
default: ""
|
||||
|
||||
# List of repositories that will be skipped
|
||||
plugin_languages_skipped:
|
||||
description: Repositories to skip
|
||||
type: array
|
||||
format: comma-separated
|
||||
default: ""
|
||||
|
||||
# Overrides
|
||||
# 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
|
||||
# Both hexadecimal and named colors are supported
|
||||
plugin_languages_colors:
|
||||
description: Custom languages colors
|
||||
type: array
|
||||
format:
|
||||
- comma-separated
|
||||
- /((?<index>[0-9])|(?<language>[-+a-z0-9#])):(?<color>#?[-a-z0-9]+)/
|
||||
default: github
|
||||
Reference in New Issue
Block a user