chore: code formatting

This commit is contained in:
github-actions[bot]
2022-10-16 18:44:18 +00:00
parent e863269d79
commit a8f95ebe5e
7 changed files with 92 additions and 89 deletions

View File

@@ -1,16 +1,16 @@
//Imports
import { Analyzer } from "./analyzer.mjs"
import fs from "fs/promises"
import linguist from "linguist-js"
import os from "os"
import paths from "path"
import linguist from "linguist-js"
import { Analyzer } from "./analyzer.mjs"
/**Indepth analyzer */
export class IndepthAnalyzer extends Analyzer {
/**Constructor */
constructor() {
super(...arguments)
this.manual = {repositories:[]}
this.manual = {repositories: []}
Object.assign(this.results, {verified: {signature: 0}})
}
@@ -74,8 +74,9 @@ export class IndepthAnalyzer extends Analyzer {
this.debug(`importing gpg ${id}`)
await this.shell.run(`gpg --import ${path}`)
}
else
else {
this.debug("skipping import of gpg keys as we are not in GitHub Actions environment")
}
}
catch (error) {
this.debug(`an error occurred while importing gpg ${id}, skipping...`)
@@ -95,14 +96,14 @@ export class IndepthAnalyzer extends Analyzer {
for (const author of this.authoring) {
//Search by --author
{
const output = await this.shell.run(`git log --author='${author}' --pretty=format:"%H" --regexp-ignore-case --no-merges`, {cwd:path, env: {LANG: "en_GB"}}, {log:false, debug:false, prefixed: false})
const output = await this.shell.run(`git log --author='${author}' --pretty=format:"%H" --regexp-ignore-case --no-merges`, {cwd: path, env: {LANG: "en_GB"}}, {log: false, debug: false, prefixed: false})
const hashes = output.split("\n").map(line => line.trim()).filter(line => this.markers.hash.test(line))
hashes.forEach(hash => commits.add(hash))
this.debug(`found ${hashes.length} for ${author} (using --author)`)
}
//Search by --grep
{
const output = await this.shell.run(`git log --grep='${author}' --pretty=format:"%H" --regexp-ignore-case --no-merges`, {cwd:path, env: {LANG: "en_GB"}}, {log:false, debug:false, prefixed: false})
const output = await this.shell.run(`git log --grep='${author}' --pretty=format:"%H" --regexp-ignore-case --no-merges`, {cwd: path, env: {LANG: "en_GB"}}, {log: false, debug: false, prefixed: false})
const hashes = output.split("\n").map(line => line.trim()).filter(line => this.markers.hash.test(line))
hashes.forEach(hash => commits.add(hash))
this.debug(`found ${hashes.length} for ${author} (using --grep)`)
@@ -111,7 +112,7 @@ export class IndepthAnalyzer extends Analyzer {
//Apply ref range if specified
if (ref) {
this.debug(`filtering commits referenced by ${ref} in ${path}`)
const output = await this.shell.run(`git rev-list --boundary ${ref}`, {cwd:path, env: {LANG: "en_GB"}}, {log:false, debug:false, prefixed: false})
const output = await this.shell.run(`git rev-list --boundary ${ref}`, {cwd: path, env: {LANG: "en_GB"}}, {log: false, debug: false, prefixed: false})
const hashes = output.split("\n").map(line => line.trim()).filter(line => this.markers.hash.test(line))
commits.forEach(commit => !hashes.includes(commit) ? commits.delete(commit) : null)
}
@@ -131,8 +132,8 @@ export class IndepthAnalyzer extends Analyzer {
try {
commits.push({
sha,
name: await this.shell.run(`git log ${sha} --format="%s (authored by %an on %cI)" --max-count=1`, {cwd: path, env: {LANG: "en_GB"}}, {log: false, debug:false, prefixed: false}),
verified: ("verified" in this.results) ? await this.shell.run(`git verify-commit ${sha}`, {cwd: path, env: {LANG: "en_GB"}}, {log: false, debug:false, prefixed: false}).then(() => true).catch(() => null) : null,
name: await this.shell.run(`git log ${sha} --format="%s (authored by %an on %cI)" --max-count=1`, {cwd: path, env: {LANG: "en_GB"}}, {log: false, debug: false, prefixed: false}),
verified: ("verified" in this.results) ? await this.shell.run(`git verify-commit ${sha}`, {cwd: path, env: {LANG: "en_GB"}}, {log: false, debug: false, prefixed: false}).then(() => true).catch(() => null) : null,
editions: await this.editions(path, {sha}),
})
}
@@ -149,8 +150,8 @@ export class IndepthAnalyzer extends Analyzer {
let edition = null
let cursor = 0
await this.shell.spawn("git", ["log", sha, "--format=''", "--max-count=1", "--patch"], {cwd: path, env: {LANG: "en_GB"}}, {
debug:false,
stdout:line => {
debug: false,
stdout: line => {
try {
//Ignore empty lines or unneeded lines
cursor++
@@ -161,26 +162,26 @@ export class IndepthAnalyzer extends Analyzer {
if (this.markers.file.test(line)) {
edition = {
path: `${path}/${line.match(this.markers.file)?.groups?.file}`.replace(/\\/g, "/"),
added: {lines:0, bytes:0},
deleted: {lines:0, bytes:0},
added: {lines: 0, bytes: 0},
deleted: {lines: 0, bytes: 0},
}
editions.push(edition)
return
}
//Line markers
if ((edition)&&(this.markers.line.test(line))) {
if ((edition) && (this.markers.line.test(line))) {
const {op = "+", content = ""} = line.match(this.markers.line)?.groups ?? {}
const size = Buffer.byteLength(content, "utf-8")
edition[{"+":"added", "-":"deleted"}[op]].bytes += size
edition[{"+":"added", "-":"deleted"}[op]].lines++
edition[{"+": "added", "-": "deleted"}[op]].bytes += size
edition[{"+": "added", "-": "deleted"}[op]].lines++
return
}
}
catch (error) {
this.debug(`skipping line ${sha}#${cursor} (${error})`)
}
}
},
})
return editions
}
@@ -193,16 +194,16 @@ export class IndepthAnalyzer extends Analyzer {
/**Run linguist against a commit and compute edited lines and bytes*/
async linguist(path, {commit, cache}) {
const result = {total:0, files:0, missed:{lines:0, bytes:0}, lines:{}, stats:{}}
const result = {total: 0, files: 0, missed: {lines: 0, bytes: 0}, lines: {}, stats: {}}
const edited = new Set()
const seen = new Set()
for (const edition of commit.editions) {
edited.add(edition.path)
//Guess file language with linguist (only run it once per sha)
if ((!(edition.path in cache.files))&&(!seen.has(commit.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, debug:false, prefixed: false})
await this.shell.run(`git checkout ${commit.sha}`, {cwd: path, env: {LANG: "en_GB"}}, {log: false, debug: false, prefixed: false})
const {files: {results: files}, languages: {results: languages}} = await linguist(path)
Object.assign(cache.files, files)
Object.assign(cache.languages, languages)
@@ -227,6 +228,4 @@ export class IndepthAnalyzer extends Analyzer {
result.files = edited.size
return result
}
}