Add options to configure which language categories to display (#477)
This commit is contained in:
@@ -59,6 +59,8 @@ For better results, it's advised to add either your surnames and eventually no-r
|
|||||||
plugin_languages_limit: 8 # Display up to 8 languages
|
plugin_languages_limit: 8 # Display up to 8 languages
|
||||||
plugin_languages_sections: most-used, recently-used # Display most used and recently used languages stats
|
plugin_languages_sections: most-used, recently-used # Display most used and recently used languages stats
|
||||||
plugin_languages_indepth: no # Get indepth stats (see documentation before enabling)
|
plugin_languages_indepth: no # Get indepth stats (see documentation before enabling)
|
||||||
|
plugin_languages_categories: programming # Display only languages that match these categories in most-used section
|
||||||
|
plugin_languages_categories: markup, programming, data # Display only languages that match these categories in recently-used section
|
||||||
plugin_languages_recent_load: 500 # Load up to 500 events to compute recently used stats
|
plugin_languages_recent_load: 500 # Load up to 500 events to compute recently used stats
|
||||||
plugin_languages_recent_days: 7 # Limit recently used stats to last week
|
plugin_languages_recent_days: 7 # Limit recently used stats to last week
|
||||||
commits_authoring: lowlighter@users.noreply.github.com # Surnames or email addresses used to identify your commits
|
commits_authoring: lowlighter@users.noreply.github.com # Surnames or email addresses used to identify your commits
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import linguist from "linguist-js"
|
import linguist from "linguist-js"
|
||||||
|
|
||||||
/**Indepth analyzer */
|
/**Indepth analyzer */
|
||||||
export async function indepth({login, data, imports, repositories}, {skipped}) {
|
export async function indepth({login, data, imports, repositories}, {skipped, categories}) {
|
||||||
|
|
||||||
//Compute repositories stats from fetched repositories
|
//Compute repositories stats from fetched repositories
|
||||||
const results = {total:0, lines:{}, stats:{}, commits:0, files:0, missed:0}
|
const results = {total:0, lines:{}, stats:{}, commits:0, files:0, missed:0}
|
||||||
@@ -29,7 +29,7 @@ export async function indepth({login, data, imports, repositories}, {skipped}) {
|
|||||||
await git.clone(`https://github.com/${repo}`, ".").status()
|
await git.clone(`https://github.com/${repo}`, ".").status()
|
||||||
|
|
||||||
//Analyze repository
|
//Analyze repository
|
||||||
await analyze(arguments[0], {results, path})
|
await analyze(arguments[0], {results, path, categories})
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.debug(`metrics/compute/${login}/plugins > languages > indepth > an error occured while processing ${repo}, skipping...`)
|
console.debug(`metrics/compute/${login}/plugins > languages > indepth > an error occured while processing ${repo}, skipping...`)
|
||||||
@@ -44,7 +44,7 @@ export async function indepth({login, data, imports, repositories}, {skipped}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**Recent languages activity */
|
/**Recent languages activity */
|
||||||
export async function recent({login, data, imports, rest, account}, {skipped = [], days = 0, load = 0, tempdir = "recent"}) {
|
export async function recent({login, data, imports, rest, account}, {skipped = [], categories, days = 0, load = 0, tempdir = "recent"}) {
|
||||||
|
|
||||||
//Get user recent activity
|
//Get user recent activity
|
||||||
console.debug(`metrics/compute/${login}/plugins > languages > querying api`)
|
console.debug(`metrics/compute/${login}/plugins > languages > querying api`)
|
||||||
@@ -118,7 +118,7 @@ export async function recent({login, data, imports, rest, account}, {skipped = [
|
|||||||
await git.init().add(".").addConfig("user.name", data.shared["commits.authoring"]?.[0] ?? login).addConfig("user.email", "<>").commit("linguist").status()
|
await git.init().add(".").addConfig("user.name", data.shared["commits.authoring"]?.[0] ?? login).addConfig("user.email", "<>").commit("linguist").status()
|
||||||
|
|
||||||
//Analyze repository
|
//Analyze repository
|
||||||
await analyze(arguments[0], {results, path:imports.paths.join(path, directory)})
|
await analyze(arguments[0], {results, path:imports.paths.join(path, directory), categories})
|
||||||
|
|
||||||
//Since we reproduce a "partial repository" with a single commit, use number of commits retrieved instead
|
//Since we reproduce a "partial repository" with a single commit, use number of commits retrieved instead
|
||||||
results.commits = commits.length
|
results.commits = commits.length
|
||||||
@@ -136,7 +136,7 @@ export async function recent({login, data, imports, rest, account}, {skipped = [
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**Analyze a single repository */
|
/**Analyze a single repository */
|
||||||
async function analyze({login, imports, data}, {results, path}) {
|
async function analyze({login, imports, data}, {results, path, categories = ["programming", "markup"]}) {
|
||||||
//Gather language data
|
//Gather language data
|
||||||
console.debug(`metrics/compute/${login}/plugins > languages > indepth > running linguist`)
|
console.debug(`metrics/compute/${login}/plugins > languages > indepth > running linguist`)
|
||||||
const {results:files, languages:languageResults} = await linguist(path)
|
const {results:files, languages:languageResults} = await linguist(path)
|
||||||
@@ -166,12 +166,12 @@ async function analyze({login, imports, data}, {results, path}) {
|
|||||||
if (/^[+]{3}\sb[/](?<file>[\s\S]+)$/.test(line)) {
|
if (/^[+]{3}\sb[/](?<file>[\s\S]+)$/.test(line)) {
|
||||||
file = line.match(/^[+]{3}\sb[/](?<file>[\s\S]+)$/)?.groups?.file.replace(/^/, `${path}/`) ?? null
|
file = line.match(/^[+]{3}\sb[/](?<file>[\s\S]+)$/)?.groups?.file.replace(/^/, `${path}/`) ?? null
|
||||||
lang = files[file] ?? null
|
lang = files[file] ?? null
|
||||||
if (lang in languageResults.data || lang in languageResults.prose)
|
if (["data", "markup", "programming", "prose"].map(type => categories.includes(type) && lang in languageResults[type]).filter(type => type).length === 0)
|
||||||
lang = null
|
lang = null
|
||||||
edited.add(file)
|
edited.add(file)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//Ignore unkonwn languages
|
//Ignore unknown languages
|
||||||
if (!lang)
|
if (!lang)
|
||||||
return
|
return
|
||||||
//Added line marker
|
//Added line marker
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//Imports
|
//Imports
|
||||||
import { indepth as indepth_analyzer, recent as recent_analyzer } from "./analyzers.mjs"
|
import {indepth as indepth_analyzer, recent as recent_analyzer} from "./analyzers.mjs"
|
||||||
|
|
||||||
//Setup
|
//Setup
|
||||||
export default async function({login, data, imports, q, rest, account}, {enabled = false, extras = false} = {}) {
|
export default async function({login, data, imports, q, rest, account}, {enabled = false, extras = false} = {}) {
|
||||||
@@ -17,7 +17,7 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Load inputs
|
//Load inputs
|
||||||
let {ignored, skipped, colors, aliases, details, threshold, limit, indepth, sections, "recent.load":_recent_load, "recent.days":_recent_days} = imports.metadata.plugins.languages.inputs({data, account, q})
|
let {ignored, skipped, colors, aliases, details, threshold, limit, indepth, sections, categories, "recent.categories":_recent_categories, "recent.load":_recent_load, "recent.days":_recent_days} = imports.metadata.plugins.languages.inputs({data, account, q})
|
||||||
threshold = (Number(threshold.replace(/%$/, "")) || 0) / 100
|
threshold = (Number(threshold.replace(/%$/, "")) || 0) / 100
|
||||||
skipped.push(...data.shared["repositories.skipped"])
|
skipped.push(...data.shared["repositories.skipped"])
|
||||||
if (!limit)
|
if (!limit)
|
||||||
@@ -57,13 +57,13 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
|||||||
//Recently used languages
|
//Recently used languages
|
||||||
if ((sections.includes("recently-used"))&&(context.mode === "user")) {
|
if ((sections.includes("recently-used"))&&(context.mode === "user")) {
|
||||||
console.debug(`metrics/compute/${login}/plugins > languages > using recent analyzer`)
|
console.debug(`metrics/compute/${login}/plugins > languages > using recent analyzer`)
|
||||||
languages["stats.recent"] = await recent_analyzer({login, data, imports, rest, account}, {skipped, days:_recent_days, load:_recent_load})
|
languages["stats.recent"] = await recent_analyzer({login, data, imports, rest, account}, {skipped, categories:_recent_categories ?? categories, days:_recent_days, load:_recent_load})
|
||||||
}
|
}
|
||||||
|
|
||||||
//Indepth mode
|
//Indepth mode
|
||||||
if (indepth) {
|
if (indepth) {
|
||||||
console.debug(`metrics/compute/${login}/plugins > languages > switching to indepth mode (this may take some time)`)
|
console.debug(`metrics/compute/${login}/plugins > languages > switching to indepth mode (this may take some time)`)
|
||||||
Object.assign(languages, await indepth_analyzer({login, data, imports, repositories}, {skipped}))
|
Object.assign(languages, await indepth_analyzer({login, data, imports, repositories}, {skipped, categories}))
|
||||||
console.debug(`metrics/compute/${login}/plugins > languages > indepth analysis missed ${languages.missed} commits`)
|
console.debug(`metrics/compute/${login}/plugins > languages > indepth analysis missed ${languages.missed} commits`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +98,30 @@ inputs:
|
|||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
|
|
||||||
|
# GitHub language categories to display
|
||||||
|
plugin_languages_categories:
|
||||||
|
description: Language categories to display
|
||||||
|
type: array
|
||||||
|
format: comma-separated
|
||||||
|
values:
|
||||||
|
- data
|
||||||
|
- markup
|
||||||
|
- programming
|
||||||
|
- prose
|
||||||
|
default: markup, programming
|
||||||
|
|
||||||
|
# GitHub language categories to display in recently-used section
|
||||||
|
plugin_languages_recent_categories:
|
||||||
|
description: Language categories to display (for recently used section)
|
||||||
|
type: array
|
||||||
|
format: comma-separated
|
||||||
|
values:
|
||||||
|
- data
|
||||||
|
- markup
|
||||||
|
- programming
|
||||||
|
- prose
|
||||||
|
default: markup, programming
|
||||||
|
|
||||||
# Number of activity events to load (for recently used languages statistics)
|
# Number of activity events to load (for recently used languages statistics)
|
||||||
# A high number will consume more requests
|
# A high number will consume more requests
|
||||||
plugin_languages_recent_load:
|
plugin_languages_recent_load:
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
plugin_languages: yes
|
plugin_languages: yes
|
||||||
plugin_languages_ignored: html, css, dockerfile
|
plugin_languages_ignored: html, css, dockerfile
|
||||||
|
|
||||||
|
|
||||||
- name: Language plugin (skipped repositories)
|
- name: Language plugin (skipped repositories)
|
||||||
uses: lowlighter/metrics@latest
|
uses: lowlighter/metrics@latest
|
||||||
with:
|
with:
|
||||||
@@ -40,6 +39,13 @@
|
|||||||
plugin_languages: yes
|
plugin_languages: yes
|
||||||
plugin_languages_threshold: 2%
|
plugin_languages_threshold: 2%
|
||||||
|
|
||||||
|
- name: Language plugin (with categories)
|
||||||
|
uses: lowlighter/metrics@latest
|
||||||
|
with:
|
||||||
|
token: MOCKED_TOKEN
|
||||||
|
plugin_languages: yes
|
||||||
|
plugin_languages_categories: programming, data
|
||||||
|
|
||||||
- name: Language plugin (complete)
|
- name: Language plugin (complete)
|
||||||
uses: lowlighter/metrics@latest
|
uses: lowlighter/metrics@latest
|
||||||
with:
|
with:
|
||||||
@@ -50,3 +56,4 @@
|
|||||||
plugin_languages_colors: rainbow
|
plugin_languages_colors: rainbow
|
||||||
plugin_languages_details: bytes-size, percentage
|
plugin_languages_details: bytes-size, percentage
|
||||||
plugin_languages_threshold: 2%
|
plugin_languages_threshold: 2%
|
||||||
|
plugin_languages_categories: programming, markup, data
|
||||||
|
|||||||
Reference in New Issue
Block a user