From 2359ad9bd788eef7a603697e8e542ec2fff5eec6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 26 Jul 2022 00:12:25 +0000 Subject: [PATCH] chore: code formatting --- source/app/metrics/utils.mjs | 4 +-- source/plugins/lines/index.mjs | 46 ++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/source/app/metrics/utils.mjs b/source/app/metrics/utils.mjs index feef0480..6ad9c247 100644 --- a/source/app/metrics/utils.mjs +++ b/source/app/metrics/utils.mjs @@ -4,6 +4,8 @@ import axios from "axios" import processes from "child_process" import crypto from "crypto" import { minify as csso } from "csso" +import * as d3 from "d3" +import D3node from "d3-node" import emoji from "emoji-name-map" import { fileTypeFromBuffer } from "file-type" import fss from "fs" @@ -30,8 +32,6 @@ import twemojis from "twemoji-parser" import url from "url" import util from "util" import xmlformat from "xml-formatter" -import * as d3 from "d3" -import D3node from "d3-node" prism_lang() //Exports diff --git a/source/plugins/lines/index.mjs b/source/plugins/lines/index.mjs index cb4cede6..5b9934ff 100644 --- a/source/plugins/lines/index.mjs +++ b/source/plugins/lines/index.mjs @@ -7,7 +7,7 @@ export default async function({login, data, imports, rest, q, account}, {enabled return null //Load inputs - let {skipped, sections, "repositories.limit":_repositories_limit, "history.limit":_history_limit} = imports.metadata.plugins.lines.inputs({data, account, q}) + let {skipped, sections, "repositories.limit": _repositories_limit, "history.limit": _history_limit} = imports.metadata.plugins.lines.inputs({data, account, q}) skipped.push(...data.shared["repositories.skipped"]) //Context @@ -23,7 +23,9 @@ export default async function({login, data, imports, rest, q, account}, {enabled //Get contributors stats from repositories console.debug(`metrics/compute/${login}/plugins > lines > querying api`) const repos = {}, weeks = {} - const response = [...await Promise.allSettled(repositories.map(async ({repo, owner}) => (skipped.includes(repo.toLocaleLowerCase())) || (skipped.includes(`${owner}/${repo}`.toLocaleLowerCase())) ? {} : {handle:`${owner}/${repo}`, stats:(await rest.repos.getContributorsStats({owner, repo})).data}))].filter(({status}) => status === "fulfilled").map(({value}) => value) + const response = [...await Promise.allSettled(repositories.map(async ({repo, owner}) => (skipped.includes(repo.toLocaleLowerCase())) || (skipped.includes(`${owner}/${repo}`.toLocaleLowerCase())) ? {} : {handle: `${owner}/${repo}`, stats: (await rest.repos.getContributorsStats({owner, repo})).data}))].filter(({status}) => status === "fulfilled").map(( + {value}, + ) => value) //Compute changed lines console.debug(`metrics/compute/${login}/plugins > lines > computing total diff`) @@ -32,7 +34,7 @@ export default async function({login, data, imports, rest, q, account}, {enabled if (!Array.isArray(stats)) return //Compute editions - repos[handle] = {added:0, deleted:0, changed:0} + repos[handle] = {added: 0, deleted: 0, changed: 0} const contributors = stats.filter(({author}) => context.mode === "repository" ? true : author?.login?.toLocaleLowerCase() === login.toLocaleLowerCase()) for (const contributor of contributors) { let added = 0, changed = 0, deleted = 0 @@ -43,7 +45,7 @@ export default async function({login, data, imports, rest, q, account}, {enabled //Compute editions per week const date = new Date(w * 1000).toISOString().substring(0, 10) if (!weeks[date]) - weeks[date] = {added:0, deleted:0, changed:0} + weeks[date] = {added: 0, deleted: 0, changed: 0} weeks[date].added += a weeks[date].deleted += d weeks[date].changed += c @@ -61,8 +63,8 @@ export default async function({login, data, imports, rest, q, account}, {enabled added: Object.entries(repos).map(([_, {added}]) => added).reduce((a, b) => a + b, 0), deleted: Object.entries(repos).map(([_, {deleted}]) => deleted).reduce((a, b) => a + b, 0), changed: Object.entries(repos).map(([_, {changed}]) => changed).reduce((a, b) => a + b, 0), - repos:Object.entries(repos).map(([handle, stats]) => ({handle, ...stats})).sort((a, b) => (b.added + b.deleted + b.changed) - (a.added + a.deleted + a.changed)).slice(0, _repositories_limit), - weeks:Object.entries(weeks).map(([date, stats]) => ({date, ...stats})).filter(({added, deleted, changed}) => added + deleted + changed).sort((a, b) => new Date(a.date) - new Date(b.date)), + repos: Object.entries(repos).map(([handle, stats]) => ({handle, ...stats})).sort((a, b) => (b.added + b.deleted + b.changed) - (a.added + a.deleted + a.changed)).slice(0, _repositories_limit), + weeks: Object.entries(weeks).map(([date, stats]) => ({date, ...stats})).filter(({added, deleted, changed}) => added + deleted + changed).sort((a, b) => new Date(a.date) - new Date(b.date)), } //Diff graphs @@ -80,36 +82,38 @@ export default async function({login, data, imports, rest, q, account}, {enabled const end = new Date(weeks.at(-1).date) const x = d3.scaleTime() .domain([start, end]) - .range([margin+offset, width-(offset+margin)]) + .range([margin + offset, width - (offset + margin)]) svg.append("g") - .attr("transform", `translate(0,${height-(offset+margin)})`) + .attr("transform", `translate(0,${height - (offset + margin)})`) .call(d3.axisBottom(x)) .selectAll("text") - .attr("transform", "translate(-5,5) rotate(-45)") - .style("text-anchor", "end") - .style("font-size", 20) + .attr("transform", "translate(-5,5) rotate(-45)") + .style("text-anchor", "end") + .style("font-size", 20) //Diff range - const points = weeks.flatMap(({added, deleted, changed}) => [added+changed, deleted+changed]) + const points = weeks.flatMap(({added, deleted, changed}) => [added + changed, deleted + changed]) const extremum = Math.max(...points) const y = d3.scaleLinear() .domain([extremum, -extremum]) - .range([margin, height-(offset+margin)]) + .range([margin, height - (offset + margin)]) svg.append("g") - .attr("transform", `translate(${margin+offset},0)`) + .attr("transform", `translate(${margin + offset},0)`) .call(d3.axisLeft(y).ticks(7).tickFormat(d3.format(".2s"))) .selectAll("text") .style("font-size", 20) //Generate history - for (const {type, sign, fill} of [{type:"added", sign:+1, fill:"rgb(63, 185, 80)"}, {type:"deleted", sign:-1, fill:"rgb(218, 54, 51)"}]) { + for (const {type, sign, fill} of [{type: "added", sign: +1, fill: "rgb(63, 185, 80)"}, {type: "deleted", sign: -1, fill: "rgb(218, 54, 51)"}]) { svg.append("path") - .datum(weeks.map(({date, ...diff}) => [new Date(date), sign*(diff[type]+diff.changed)])) - .attr("d", d3.area() - .x(d => x(d[0])) - .y0(d => y(d[1])) - .y1(() => y(0)) - ) + .datum(weeks.map(({date, ...diff}) => [new Date(date), sign * (diff[type] + diff.changed)])) + .attr( + "d", + d3.area() + .x(d => x(d[0])) + .y0(d => y(d[1])) + .y1(() => y(0)), + ) .attr("fill", fill) } result.history = d3n.svgString()