feat(plugins/languages): add plugin_languages_analysis_timeout to avoid long runs (#572) [skip ci]
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
import linguist from "linguist-js"
|
||||
|
||||
/**Indepth analyzer */
|
||||
export async function indepth({login, data, imports, repositories}, {skipped, categories}) {
|
||||
export async function indepth({login, data, imports, repositories}, {skipped, categories, timeout}) {
|
||||
return new Promise(async (solve, reject) => {
|
||||
//Timeout
|
||||
if (Number.isFinite(timeout)) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > timeout set to ${timeout}m`)
|
||||
setTimeout(() => reject(`Reached maximum execution time of ${timeout}m for analysis`), timeout * 60 * 1000)
|
||||
}
|
||||
|
||||
//Compute repositories stats from fetched repositories
|
||||
const results = {total:0, lines:{}, stats:{}, colors:{}, commits:0, files:0, missed:0}
|
||||
@@ -40,11 +46,18 @@ export async function indepth({login, data, imports, repositories}, {skipped, ca
|
||||
await imports.fs.rm(path, {recursive:true, force:true})
|
||||
}
|
||||
}
|
||||
return results
|
||||
solve(results)
|
||||
})
|
||||
}
|
||||
|
||||
/**Recent languages activity */
|
||||
export async function recent({login, data, imports, rest, account}, {skipped = [], categories, days = 0, load = 0, tempdir = "recent"}) {
|
||||
export async function recent({login, data, imports, rest, account}, {skipped = [], categories, days = 0, load = 0, tempdir = "recent", timeout}) {
|
||||
return new Promise(async (solve, reject) => {
|
||||
//Timeout
|
||||
if (Number.isFinite(timeout)) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > timeout set to ${timeout}m`)
|
||||
setTimeout(() => reject(`Reached maximum execution time of ${timeout}m for analysis`), timeout * 60 * 1000)
|
||||
}
|
||||
|
||||
//Get user recent activity
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > querying api`)
|
||||
@@ -134,7 +147,8 @@ export async function recent({login, data, imports, rest, account}, {skipped = [
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > cleaning temp dir ${path}`)
|
||||
await imports.fs.rm(path, {recursive:true, force:true})
|
||||
}
|
||||
return results
|
||||
solve(results)
|
||||
})
|
||||
}
|
||||
|
||||
/**Analyze a single repository */
|
||||
|
||||
@@ -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, categories, "recent.categories":_recent_categories, "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, "analysis.timeout":timeout, 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)
|
||||
@@ -60,19 +60,29 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
||||
if (extras) {
|
||||
//Recently used languages
|
||||
if ((sections.includes("recently-used"))&&(context.mode === "user")) {
|
||||
try {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > using recent analyzer`)
|
||||
languages["stats.recent"] = await recent_analyzer({login, data, imports, rest, account}, {skipped, categories:_recent_categories ?? categories, 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, timeout})
|
||||
Object.assign(languages.colors, languages["stats.recent"].colors)
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > ${error}`)
|
||||
}
|
||||
}
|
||||
|
||||
//Indepth mode
|
||||
if (indepth) {
|
||||
try {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > switching to indepth mode (this may take some time)`)
|
||||
const existingColors = languages.colors
|
||||
Object.assign(languages, await indepth_analyzer({login, data, imports, repositories}, {skipped, categories}))
|
||||
Object.assign(languages, await indepth_analyzer({login, data, imports, repositories}, {skipped, categories, timeout}))
|
||||
Object.assign(languages.colors, existingColors)
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > indepth analysis missed ${languages.missed} commits`)
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > ${error}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Compute languages stats
|
||||
|
||||
@@ -98,6 +98,17 @@ inputs:
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
# Analysis timeout (in minutes)
|
||||
# In case of timeout, it'll automatically fallback to default algorithm
|
||||
# Please be nice with GitHub Actions and disable `plugin_languages_indepth` if your account is not supported
|
||||
# See documentation before enabling
|
||||
plugin_languages_analysis_timeout:
|
||||
description: Languages analysis timeout
|
||||
type: number
|
||||
default: 15
|
||||
min: 1
|
||||
max: 30
|
||||
|
||||
# GitHub language categories to display
|
||||
plugin_languages_categories:
|
||||
description: Language categories to display
|
||||
|
||||
Reference in New Issue
Block a user