Add customizable recent_load and recent_days options
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -89,3 +89,21 @@ inputs:
|
||||
description: Indepth languages processing (see documentation before enabling)
|
||||
type: boolean
|
||||
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
|
||||
@@ -18,6 +18,11 @@
|
||||
</div>
|
||||
</section>
|
||||
<% } else { const width = 460 * (1 + large) %>
|
||||
<% if (section === "recently-used") { %>
|
||||
<small>
|
||||
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) %>
|
||||
</small>
|
||||
<% } %>
|
||||
<svg class="bar" xmlns="http://www.w3.org/2000/svg" width="<%= width %>" height="8">
|
||||
<mask id="languages-bar">
|
||||
<rect x="0" y="0" width="<%= width %>" height="8" fill="white" rx="5"/>
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
</div>
|
||||
</section>
|
||||
<% } else { const width = 460 * (1 + large) %>
|
||||
<% if (section === "recently-used") { %>
|
||||
<small>
|
||||
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) %>
|
||||
</small>
|
||||
<% } %>
|
||||
<svg class="bar" xmlns="http://www.w3.org/2000/svg" width="<%= width %>" height="8">
|
||||
<mask id="languages-bar">
|
||||
<rect x="0" y="0" width="<%= width %>" height="8" fill="white" rx="5"/>
|
||||
|
||||
Reference in New Issue
Block a user