From 47473327b00d6d2566707142f421bbfb86e55c95 Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Thu, 27 May 2021 12:22:31 +0200 Subject: [PATCH] Add customizable `recent_load` and `recent_days` options --- source/plugins/languages/analyzers.mjs | 6 ++++-- source/plugins/languages/index.mjs | 4 ++-- source/plugins/languages/metadata.yml | 20 ++++++++++++++++++- .../templates/classic/partials/languages.ejs | 5 +++++ .../repository/partials/languages.ejs | 5 +++++ 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/source/plugins/languages/analyzers.mjs b/source/plugins/languages/analyzers.mjs index 13a2d14e..82b5841d 100644 --- a/source/plugins/languages/analyzers.mjs +++ b/source/plugins/languages/analyzers.mjs @@ -45,14 +45,14 @@ export async function indepth({login, data, imports, repositories}, {skipped}) { } /**Recent languages activity */ -export async function recent({login, data, imports, rest, account}, {skipped}) { +export async function recent({login, data, imports, rest, account}, {skipped, days = 0, load = 0}) { //Check prerequisites if (!await imports.which("github-linguist")) throw new Error("Feature requires github-linguist") //Get user recent activity console.debug(`metrics/compute/${login}/plugins > languages > querying api`) - const commits = [], days = 14, pages = 3, results = {total:0, lines:{}, stats:{}} + const commits = [], pages = Math.ceil(load/100), results = {total:0, lines:{}, stats:{}, commits:0, files:0, days} try { for (let page = 1; page <= pages; page++) { console.debug(`metrics/compute/${login}/plugins > languages > loading page ${page}`) @@ -68,6 +68,7 @@ export async function recent({login, data, imports, rest, account}, {skipped}) { console.debug(`metrics/compute/${login}/plugins > languages > no more page to load`) } console.debug(`metrics/compute/${login}/plugins > languages > ${commits.length} commits loaded`) + results.commits = commits.length //Retrieve edited files and filter edited lines (those starting with +/-) from patches console.debug(`metrics/compute/${login}/plugins > languages > loading patches`) @@ -86,6 +87,7 @@ export async function recent({login, data, imports, rest, account}, {skipped}) { //Temporary directory const path = imports.paths.join(imports.os.tmpdir(), `${data.user.databaseId}`) console.debug(`metrics/compute/${login}/plugins > languages > creating temp dir ${path} with ${patches.length} files`) + results.files = patches.length //Process try { diff --git a/source/plugins/languages/index.mjs b/source/plugins/languages/index.mjs index ed12dabb..8d42a1fc 100644 --- a/source/plugins/languages/index.mjs +++ b/source/plugins/languages/index.mjs @@ -17,7 +17,7 @@ export default async function({login, data, imports, q, rest, account}, {enabled } //Load inputs - let {ignored, skipped, colors, details, threshold, limit, indepth, sections} = imports.metadata.plugins.languages.inputs({data, account, q}) + let {ignored, skipped, colors, details, threshold, limit, indepth, sections, "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) @@ -54,7 +54,7 @@ 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}) + languages["stats.recent"] = await recent_analyzer({login, data, imports, rest, account}, {skipped, days:_recent_days, load:_recent_load}) } //Indepth mode diff --git a/source/plugins/languages/metadata.yml b/source/plugins/languages/metadata.yml index d91f7d84..20558845 100644 --- a/source/plugins/languages/metadata.yml +++ b/source/plugins/languages/metadata.yml @@ -88,4 +88,22 @@ inputs: plugin_languages_indepth: description: Indepth languages processing (see documentation before enabling) type: boolean - default: false \ No newline at end of file + default: false + + # Number of activity events to load (for recently used languages statistics) + # A high number will consume more requests + plugin_languages_recent_load: + description: Number of events to load (for recently used section) + type: number + default: 300 + min: 100 + max: 1000 + + # Filter events by age (for recently used languages statistics) + # Set to 0 to disable age filtering + plugin_languages_recent_days: + description: Maximum event age (for recently used section) + type: number + default: 14 + min: 0 + max: 365 \ No newline at end of file diff --git a/source/templates/classic/partials/languages.ejs b/source/templates/classic/partials/languages.ejs index 68d38ce8..615e3366 100644 --- a/source/templates/classic/partials/languages.ejs +++ b/source/templates/classic/partials/languages.ejs @@ -18,6 +18,11 @@ <% } else { const width = 460 * (1 + large) %> + <% if (section === "recently-used") { %> + + estimation from <%= plugins.languages["stats.recent"]?.files %> edited file<%= s(plugins.languages["stats.recent"]?.files) %> from <%= plugins.languages["stats.recent"]?.commits %> commit<%= s(plugins.languages["stats.recent"]?.commits) %> over last <%= plugins.languages["stats.recent"]?.days %> day<%= s(plugins.languages["stats.recent"]?.days) %> + + <% } %> diff --git a/source/templates/repository/partials/languages.ejs b/source/templates/repository/partials/languages.ejs index 68d38ce8..615e3366 100644 --- a/source/templates/repository/partials/languages.ejs +++ b/source/templates/repository/partials/languages.ejs @@ -18,6 +18,11 @@ <% } else { const width = 460 * (1 + large) %> + <% if (section === "recently-used") { %> + + estimation from <%= plugins.languages["stats.recent"]?.files %> edited file<%= s(plugins.languages["stats.recent"]?.files) %> from <%= plugins.languages["stats.recent"]?.commits %> commit<%= s(plugins.languages["stats.recent"]?.commits) %> over last <%= plugins.languages["stats.recent"]?.days %> day<%= s(plugins.languages["stats.recent"]?.days) %> + + <% } %>