Improvements languages indepth analysis (#329)
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
/**Indepth analyzer */
|
||||
export async function indepth({login, data, imports}, {skipped}) {
|
||||
export async function indepth({login, data, imports, repositories}, {skipped}) {
|
||||
//Check prerequisites
|
||||
if (!await imports.which("github-linguist"))
|
||||
throw new Error("Feature requires github-linguist")
|
||||
|
||||
//Compute repositories stats from fetched repositories
|
||||
const results = {total:0, stats:{}}
|
||||
for (const repository of data.user.repositories.nodes) {
|
||||
const results = {total:0, lines:{}, stats:{}}
|
||||
for (const repository of repositories) {
|
||||
//Skip repository if asked
|
||||
if ((skipped.includes(repository.name.toLocaleLowerCase())) || (skipped.includes(`${repository.owner.login}/${repository.name}`.toLocaleLowerCase()))) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > skipped repository ${repository.owner.login}/${repository.name}`)
|
||||
@@ -52,7 +52,7 @@ export async function recent({login, data, imports, rest, account}, {skipped}) {
|
||||
|
||||
//Get user recent activity
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > querying api`)
|
||||
const commits = [], days = 14, pages = 3, results = {total:0, stats:{}}
|
||||
const commits = [], days = 14, pages = 3, results = {total:0, lines:{}, stats:{}}
|
||||
try {
|
||||
for (let page = 1; page <= pages; page++) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > loading page ${page}`)
|
||||
@@ -110,8 +110,6 @@ export async function recent({login, data, imports, rest, account}, {skipped}) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > cleaning temp dir ${path}`)
|
||||
await imports.fs.rmdir(path, {recursive:true})
|
||||
}
|
||||
|
||||
console.log(results)
|
||||
return results
|
||||
}
|
||||
|
||||
@@ -121,8 +119,6 @@ async function analyze({login, imports}, {results, path}) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > indepth > running linguist`)
|
||||
const files = Object.fromEntries(Object.entries(JSON.parse(await imports.run("github-linguist --json", {cwd:path}, {log:false}))).flatMap(([lang, files]) => files.map(file => [file, lang])))
|
||||
|
||||
console.log(files)
|
||||
|
||||
//Processing diff
|
||||
const per_page = 10
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > indepth > checking git log`)
|
||||
@@ -149,9 +145,10 @@ async function analyze({login, imports}, {results, path}) {
|
||||
if (!lang)
|
||||
continue
|
||||
//Added line marker
|
||||
if (/^[+]\s(?<line>[\s\S]+)$/.test(line)) {
|
||||
const size = Buffer.byteLength(line.match(/^[+]\s(?<line>[\s\S]+)$/)?.groups?.line ?? "", "utf-8")
|
||||
if (/^[+]\s*(?<line>[\s\S]+)$/.test(line)) {
|
||||
const size = Buffer.byteLength(line.match(/^[+]\s*(?<line>[\s\S]+)$/)?.groups?.line ?? "", "utf-8")
|
||||
results.stats[lang] = (results.stats[lang] ?? 0) + size
|
||||
results.lines[lang] = (results.lines[lang] ?? 0) + 1
|
||||
results.total += size
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user