diff --git a/README.md b/README.md index d6144494..ce0f5089 100644 --- a/README.md +++ b/README.md @@ -565,7 +565,7 @@ The default template is `classic`. ✔️ ✔️ ✔️ - ✔️ + ✔️N ✔️ ✔️ ✔️ @@ -1015,6 +1015,22 @@ Add the following to your workflow: plugin_languages_skipped: "" # List of comma separated repositories to skip ``` + 🚧 Feature below is available as pre-release on @master branch (unstable) + +It is possible to use custom colors for languages if those provided by GitHub do not suit you by adding the following to your workflow: +```yaml +- uses: lowlighter/metrics@latest + with: + # ... other options + plugin_languages: yes + plugin_languages_colors: "0:orange, javascript:#ff0000, ..." # Make most used languages orange and JavaScript red +``` + +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). + +Use the special value `rainbow` to use rainbow colors. + ### 🎟️ Follow-up diff --git a/action.yml b/action.yml index 40274ff1..2a1ae101 100644 --- a/action.yml +++ b/action.yml @@ -211,6 +211,17 @@ inputs: description: List of skipped repositories default: "" + # List of custom colors for specified languages + # Use this option when GitHub's color are too similar for your most used languages + # + # It is possible to use either hexadecimal colors or named colors + # - Use "rainbow" values for a predefined set of 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) + plugin_languages_colors: + description: Custom languages colors + default: "" + # Follow-up plugin # Display the number and the ratio of opened/closed issues and opened/merged pull requests on your repositories plugin_followup: diff --git a/source/app/action/index.mjs b/source/app/action/index.mjs index cf8b5e48..ee358cc4 100644 --- a/source/app/action/index.mjs +++ b/source/app/action/index.mjs @@ -166,7 +166,7 @@ } //Languages if (plugins.languages.enabled) { - for (const option of ["ignored", "skipped"]) + for (const option of ["ignored", "skipped", "colors"]) info(`Languages ${option}`, q[`languages.${option}`] = input.array(`plugin_languages_${option}`)) } //Habits diff --git a/source/plugins/languages/index.mjs b/source/plugins/languages/index.mjs index edf53d59..fed20962 100644 --- a/source/plugins/languages/index.mjs +++ b/source/plugins/languages/index.mjs @@ -6,11 +6,16 @@ if ((!enabled)||(!q.languages)) return null //Parameters override - let {"languages.ignored":ignored = "", "languages.skipped":skipped = ""} = q + 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 + if (`${colors}` === "rainbow") + colors = ["0:#ff0000", "1:#ffa500", "2:#ffff00", "3:#008000", "4:#0000ff", "5:#4b0082", "6:#ee82ee", "7:#162221"] + 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:{}} @@ -29,7 +34,7 @@ } //Update language stats languages.stats[name] = (languages.stats[name] ?? 0) + size - languages.colors[name] = color ?? "#ededed" + languages.colors[name] = colors[name.toLocaleLowerCase()] ?? color ?? "#ededed" languages.total += size } } @@ -37,8 +42,11 @@ 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})) - for (let i = 1; i < languages.favorites.length; i++) - languages.favorites[i].x = languages.favorites[i-1].x + languages.favorites[i-1].value + for (let i = 0; i < languages.favorites.length; i++) { + 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] + } //Results return languages } diff --git a/tests/metrics.test.js b/tests/metrics.test.js index bc16fe58..c7c8e250 100644 --- a/tests/metrics.test.js +++ b/tests/metrics.test.js @@ -138,10 +138,19 @@ plugin_languages:true, plugin_languages_skipped:"metrics", }], + ["Language plugin (custom color set)", { + plugin_languages:true, + plugin_languages_colors:"0:ff0000,1:red", + }], + ["Language plugin (custom color set)", { + plugin_languages:true, + plugin_languages_colors:"rainbow", + }], ["Language plugin (complete)", { plugin_languages:true, plugin_languages_ignored:"html, css, dockerfile", plugin_languages_skipped:"metrics", + plugin_languages_colors:"rainbow", }], ["Follow-up plugin (default)", { plugin_followup:true,