Skip to content

Commit 4747332

Browse files
committed
Add customizable recent_load and recent_days options
1 parent 123e613 commit 4747332

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

source/plugins/languages/analyzers.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ export async function indepth({login, data, imports, repositories}, {skipped}) {
4545
}
4646

4747
/**Recent languages activity */
48-
export async function recent({login, data, imports, rest, account}, {skipped}) {
48+
export async function recent({login, data, imports, rest, account}, {skipped, days = 0, load = 0}) {
4949
//Check prerequisites
5050
if (!await imports.which("github-linguist"))
5151
throw new Error("Feature requires github-linguist")
5252

5353
//Get user recent activity
5454
console.debug(`metrics/compute/${login}/plugins > languages > querying api`)
55-
const commits = [], days = 14, pages = 3, results = {total:0, lines:{}, stats:{}}
55+
const commits = [], pages = Math.ceil(load/100), results = {total:0, lines:{}, stats:{}, commits:0, files:0, days}
5656
try {
5757
for (let page = 1; page <= pages; page++) {
5858
console.debug(`metrics/compute/${login}/plugins > languages > loading page ${page}`)
@@ -68,6 +68,7 @@ export async function recent({login, data, imports, rest, account}, {skipped}) {
6868
console.debug(`metrics/compute/${login}/plugins > languages > no more page to load`)
6969
}
7070
console.debug(`metrics/compute/${login}/plugins > languages > ${commits.length} commits loaded`)
71+
results.commits = commits.length
7172

7273
//Retrieve edited files and filter edited lines (those starting with +/-) from patches
7374
console.debug(`metrics/compute/${login}/plugins > languages > loading patches`)
@@ -86,6 +87,7 @@ export async function recent({login, data, imports, rest, account}, {skipped}) {
8687
//Temporary directory
8788
const path = imports.paths.join(imports.os.tmpdir(), `${data.user.databaseId}`)
8889
console.debug(`metrics/compute/${login}/plugins > languages > creating temp dir ${path} with ${patches.length} files`)
90+
results.files = patches.length
8991

9092
//Process
9193
try {

source/plugins/languages/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default async function({login, data, imports, q, rest, account}, {enabled
1717
}
1818

1919
//Load inputs
20-
let {ignored, skipped, colors, details, threshold, limit, indepth, sections} = imports.metadata.plugins.languages.inputs({data, account, q})
20+
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})
2121
threshold = (Number(threshold.replace(/%$/, "")) || 0) / 100
2222
skipped.push(...data.shared["repositories.skipped"])
2323
if (!limit)
@@ -54,7 +54,7 @@ export default async function({login, data, imports, q, rest, account}, {enabled
5454
//Recently used languages
5555
if ((sections.includes("recently-used"))&&(context.mode === "user")) {
5656
console.debug(`metrics/compute/${login}/plugins > languages > using recent analyzer`)
57-
languages["stats.recent"] = await recent_analyzer({login, data, imports, rest, account}, {skipped})
57+
languages["stats.recent"] = await recent_analyzer({login, data, imports, rest, account}, {skipped, days:_recent_days, load:_recent_load})
5858
}
5959

6060
//Indepth mode

source/plugins/languages/metadata.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,22 @@ inputs:
8888
plugin_languages_indepth:
8989
description: Indepth languages processing (see documentation before enabling)
9090
type: boolean
91-
default: false
91+
default: false
92+
93+
# Number of activity events to load (for recently used languages statistics)
94+
# A high number will consume more requests
95+
plugin_languages_recent_load:
96+
description: Number of events to load (for recently used section)
97+
type: number
98+
default: 300
99+
min: 100
100+
max: 1000
101+
102+
# Filter events by age (for recently used languages statistics)
103+
# Set to 0 to disable age filtering
104+
plugin_languages_recent_days:
105+
description: Maximum event age (for recently used section)
106+
type: number
107+
default: 14
108+
min: 0
109+
max: 365

source/templates/classic/partials/languages.ejs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
</div>
1919
</section>
2020
<% } else { const width = 460 * (1 + large) %>
21+
<% if (section === "recently-used") { %>
22+
<small>
23+
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) %>
24+
</small>
25+
<% } %>
2126
<svg class="bar" xmlns="http://www.w3.org/2000/svg" width="<%= width %>" height="8">
2227
<mask id="languages-bar">
2328
<rect x="0" y="0" width="<%= width %>" height="8" fill="white" rx="5"/>

source/templates/repository/partials/languages.ejs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
</div>
1919
</section>
2020
<% } else { const width = 460 * (1 + large) %>
21+
<% if (section === "recently-used") { %>
22+
<small>
23+
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) %>
24+
</small>
25+
<% } %>
2126
<svg class="bar" xmlns="http://www.w3.org/2000/svg" width="<%= width %>" height="8">
2227
<mask id="languages-bar">
2328
<rect x="0" y="0" width="<%= width %>" height="8" fill="white" rx="5"/>

0 commit comments

Comments
 (0)