From 66073f6686e8919d732b052461036a71a3dda1b0 Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Wed, 5 Oct 2022 20:42:22 -0400 Subject: [PATCH] improvements --- source/plugins/languages/analyzer/analyzer.mjs | 6 ++++-- source/plugins/languages/analyzer/indepth.mjs | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/plugins/languages/analyzer/analyzer.mjs b/source/plugins/languages/analyzer/analyzer.mjs index eed654baafd..0c61409b817 100644 --- a/source/plugins/languages/analyzer/analyzer.mjs +++ b/source/plugins/languages/analyzer/analyzer.mjs @@ -61,8 +61,10 @@ export class Analyzer { throw new TypeError(`"${repository}" pattern is not supported`) const {login, name, ...groups} = repository.match(this.parser)?.groups ?? {} repository = {owner:{login}, name} - branch = branch ?? groups.branch - ref = ref ?? groups.ref + if (groups.branch) + branch = groups.branch + if (groups.ref) + ref = groups.ref } const repo = `${repository.owner.login}/${repository.name}` const path = paths.join(os.tmpdir(), `${this.uid}-${repo.replace(/[^\w]/g, "_")}`) diff --git a/source/plugins/languages/analyzer/indepth.mjs b/source/plugins/languages/analyzer/indepth.mjs index 0ab5735d035..c862548f8b6 100644 --- a/source/plugins/languages/analyzer/indepth.mjs +++ b/source/plugins/languages/analyzer/indepth.mjs @@ -184,16 +184,18 @@ export class IndepthAnalyzer extends Analyzer { const cache = {files:{}, languages:{}} const result = {total:0, files:0, missed:{lines:0, bytes:0}, lines:{}, stats:{}, languages:{}} const edited = new Set() + const seen = new Set() for (const edition of commit.editions) { edited.add(edition.path) - //Guess file language with linguist - if (!(edition.path in cache.files)) { + //Guess file language with linguist (only run it once per sha) + if ((!(edition.path in cache.files))&&(!seen.has(commit.sha))) { this.debug(`language for file ${edition.path} is not in cache, running linguist at ${commit.sha}`) await this.shell.run(`git checkout ${commit.sha}`, {cwd: path, env: {LANG: "en_GB"}}, {log: false, prefixed: false}) const {files: {results: files}, languages: {results: languages}} = await linguist(path) Object.assign(cache.files, files) Object.assign(cache.languages, languages) + seen.add(commit.sha) } if (!(edition.path in cache.files)) cache.files[edition.path] = ""