Add options to configure which language categories to display (#477)

This commit is contained in:
Nixinova
2021-08-17 22:08:49 +12:00
committed by GitHub
parent 34004e8909
commit 7534c37ab8
5 changed files with 45 additions and 12 deletions

View File

@@ -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_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_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_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

View File

@@ -1,7 +1,7 @@
import linguist from "linguist-js"
/**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
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()
//Analyze repository
await analyze(arguments[0], {results, path})
await analyze(arguments[0], {results, path, categories})
}
catch (error) {
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 */
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
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()
//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
results.commits = commits.length
@@ -136,7 +136,7 @@ export async function recent({login, data, imports, rest, account}, {skipped = [
}
/**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
console.debug(`metrics/compute/${login}/plugins > languages > indepth > running linguist`)
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)) {
file = line.match(/^[+]{3}\sb[/](?<file>[\s\S]+)$/)?.groups?.file.replace(/^/, `${path}/`) ?? 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
edited.add(file)
return
}
//Ignore unkonwn languages
//Ignore unknown languages
if (!lang)
return
//Added line marker

View File

@@ -17,7 +17,7 @@ export default async function({login, data, imports, q, rest, account}, {enabled
}
//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
skipped.push(...data.shared["repositories.skipped"])
if (!limit)
@@ -57,13 +57,13 @@ export default async function({login, data, imports, q, rest, account}, {enabled
//Recently used languages
if ((sections.includes("recently-used"))&&(context.mode === "user")) {
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
if (indepth) {
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`)
}
}

View File

@@ -98,6 +98,30 @@ inputs:
type: boolean
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)
# A high number will consume more requests
plugin_languages_recent_load:

View File

@@ -11,7 +11,6 @@
plugin_languages: yes
plugin_languages_ignored: html, css, dockerfile
- name: Language plugin (skipped repositories)
uses: lowlighter/metrics@latest
with:
@@ -40,6 +39,13 @@
plugin_languages: yes
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)
uses: lowlighter/metrics@latest
with:
@@ -50,3 +56,4 @@
plugin_languages_colors: rainbow
plugin_languages_details: bytes-size, percentage
plugin_languages_threshold: 2%
plugin_languages_categories: programming, markup, data