fix(plugins/languages): ensure lang is defined before checking categories (ref #513) (#529)

This commit is contained in:
Simon Lecoq
2021-09-07 20:14:28 +02:00
committed by GitHub
parent fd6f69738c
commit af8c476548

View File

@@ -154,6 +154,7 @@ async function analyze({login, imports, data}, {results, path, categories = ["pr
let empty = true, file = null, lang = null let empty = true, file = null, lang = null
await imports.spawn("git", ["log", ...data.shared["commits.authoring"].map(authoring => `--author="${authoring}"`), "--regexp-ignore-case", "--format=short", "--patch", `--max-count=${per_page}`, `--skip=${page*per_page}`], {cwd:path}, { await imports.spawn("git", ["log", ...data.shared["commits.authoring"].map(authoring => `--author="${authoring}"`), "--regexp-ignore-case", "--format=short", "--patch", `--max-count=${per_page}`, `--skip=${page*per_page}`], {cwd:path}, {
stdout(line) { stdout(line) {
try {
//Unflag empty output //Unflag empty output
if ((empty)&&(line.trim().length)) if ((empty)&&(line.trim().length))
empty = false empty = false
@@ -168,8 +169,8 @@ async function analyze({login, imports, data}, {results, path, categories = ["pr
//File marker //File marker
if (/^[+]{3}\sb[/](?<file>[\s\S]+)$/.test(line)) { if (/^[+]{3}\sb[/](?<file>[\s\S]+)$/.test(line)) {
file = `${path}/${line.match(/^[+]{3}\sb[/](?<file>[\s\S]+)$/)?.groups?.file}`.replace(/\\/g, "/") file = `${path}/${line.match(/^[+]{3}\sb[/](?<file>[\s\S]+)$/)?.groups?.file}`.replace(/\\/g, "/")
lang = files[file] lang = files[file] ?? null
if (!categories.includes(languageResults[lang].type)) if ((lang)&&(!categories.includes(languageResults[lang].type)))
lang = null lang = null
edited.add(file) edited.add(file)
return return
@@ -185,6 +186,10 @@ async function analyze({login, imports, data}, {results, path, categories = ["pr
results.total += size results.total += size
} }
} }
catch (error) {
console.debug(`metrics/compute/${login}/plugins > languages > indepth > an error occured while processing line (${error.message}), skipping...`)
}
}
}) })
if (empty) { if (empty) {
console.debug(`metrics/compute/${login}/plugins > languages > indepth > no more commits`) console.debug(`metrics/compute/${login}/plugins > languages > indepth > no more commits`)