chore: code formatting
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//Imports
|
||||
import {indepth as indepth_analyzer, recent as recent_analyzer} from "./analyzers.mjs"
|
||||
import { indepth as indepth_analyzer, recent as recent_analyzer } from "./analyzers.mjs"
|
||||
|
||||
//Setup
|
||||
export default async function({login, data, imports, q, rest, account}, {enabled = false, extras = false} = {}) {
|
||||
@@ -10,14 +10,14 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
||||
return null
|
||||
|
||||
//Context
|
||||
let context = {mode:"user"}
|
||||
let context = {mode: "user"}
|
||||
if (q.repo) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > switched to repository mode`)
|
||||
context = {...context, mode:"repository"}
|
||||
context = {...context, mode: "repository"}
|
||||
}
|
||||
|
||||
//Load inputs
|
||||
let {ignored, skipped, other, 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
|
||||
let {ignored, skipped, other, 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,
|
||||
@@ -40,11 +40,11 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
||||
|
||||
//Unique languages
|
||||
const repositories = [...data.user.repositories.nodes, ...data.user.repositoriesContributedTo.nodes]
|
||||
const unique = new Set(repositories.flatMap(repository => repository.languages.edges.map(({node:{name}}) => name))).size
|
||||
const unique = new Set(repositories.flatMap(repository => repository.languages.edges.map(({node: {name}}) => name))).size
|
||||
|
||||
//Iterate through user's repositories and retrieve languages data
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > processing ${data.user.repositories.nodes.length} repositories`)
|
||||
const languages = {unique, sections, details, indepth, colors:{}, total:0, stats:{}, "stats.recent":{}}
|
||||
const languages = {unique, sections, details, indepth, colors: {}, total: 0, stats: {}, "stats.recent": {}}
|
||||
const customColors = {}
|
||||
for (const repository of data.user.repositories.nodes) {
|
||||
//Skip repository if asked
|
||||
@@ -53,7 +53,7 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
||||
continue
|
||||
}
|
||||
//Process repository languages
|
||||
for (const {size, node:{color, name}} of Object.values(repository.languages.edges)) {
|
||||
for (const {size, node: {color, name}} of Object.values(repository.languages.edges)) {
|
||||
languages.stats[name] = (languages.stats[name] ?? 0) + size
|
||||
if (colors[name.toLocaleLowerCase()])
|
||||
customColors[name] = colors[name.toLocaleLowerCase()]
|
||||
@@ -69,7 +69,7 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
||||
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, timeout})
|
||||
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) {
|
||||
@@ -83,8 +83,8 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
||||
const gpg = []
|
||||
try {
|
||||
for (const username of [login, "web-flow"]) {
|
||||
const {data:keys} = await rest.users.listGpgKeysForUser({username})
|
||||
gpg.push(...keys.map(({key_id:id, raw_key:pub, emails}) => ({id, pub, emails})))
|
||||
const {data: keys} = await rest.users.listGpgKeysForUser({username})
|
||||
gpg.push(...keys.map(({key_id: id, raw_key: pub, emails}) => ({id, pub, emails})))
|
||||
if (username === login) {
|
||||
for (const {email} of gpg.flatMap(({emails}) => emails)) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > auto-adding ${email} to commits_authoring (fetched from gpg)`)
|
||||
@@ -126,9 +126,10 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
||||
}
|
||||
|
||||
//Compute languages stats
|
||||
for (const {section, stats = {}, lines = {}, missed = {bytes:0}, total = 0} of [{section:"favorites", stats:languages.stats, lines:languages.lines, total:languages.total, missed:languages.missed}, {section:"recent", ...languages["stats.recent"]}]) {
|
||||
for (const {section, stats = {}, lines = {}, missed = {bytes: 0}, total = 0} of [{section: "favorites", stats: languages.stats, lines: languages.lines, total: languages.total, missed: languages.missed}, {section: "recent", ...languages["stats.recent"]}]) {
|
||||
console.debug(`metrics/compute/${login}/plugins > languages > computing stats ${section}`)
|
||||
languages[section] = Object.entries(stats).filter(([name]) => !ignored.includes(name.toLocaleLowerCase())).sort(([_an, a], [_bn, b]) => b - a).slice(0, limit).map(([name, value]) => ({name, value, size:value, color:languages.colors[name], x:0})).filter(({value}) => value / total > threshold
|
||||
languages[section] = Object.entries(stats).filter(([name]) => !ignored.includes(name.toLocaleLowerCase())).sort(([_an, a], [_bn, b]) => b - a).slice(0, limit).map(([name, value]) => ({name, value, size: value, color: languages.colors[name], x: 0})).filter(({value}) =>
|
||||
value / total > threshold
|
||||
)
|
||||
if (other) {
|
||||
let value = indepth ? missed.bytes : Object.entries(stats).filter(([name]) => !Object.values(languages[section]).map(({name}) => name).includes(name)).reduce((a, [_, b]) => a + b, 0)
|
||||
@@ -141,7 +142,7 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
||||
languages[section].push({name:"Other", value, size:value, get lines() { return missed.lines }, set lines(_) { }, x:0}) //eslint-disable-line brace-style, no-empty-function, max-statements-per-line
|
||||
}
|
||||
}
|
||||
const visible = {total:Object.values(languages[section]).map(({size}) => size).reduce((a, b) => a + b, 0)}
|
||||
const visible = {total: Object.values(languages[section]).map(({size}) => size).reduce((a, b) => a + b, 0)}
|
||||
for (let i = 0; i < languages[section].length; i++) {
|
||||
const {name} = languages[section][i]
|
||||
languages[section][i].value /= visible.total
|
||||
@@ -159,6 +160,6 @@ export default async function({login, data, imports, q, rest, account}, {enabled
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error:{message:"An error occured", instance:error}}
|
||||
throw {error: {message: "An error occured", instance: error}}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user