chore: code formatting
This commit is contained in:
@@ -7,7 +7,7 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {limit, ignored, only, "limit.repositories":_limit, languages, "limit.languages":_limit_languages, "shuffle.repositories":_shuffle} = imports.metadata.plugins.starlists.inputs({data, account, q})
|
||||
let {limit, ignored, only, "limit.repositories": _limit, languages, "limit.languages": _limit_languages, "shuffle.repositories": _shuffle} = imports.metadata.plugins.starlists.inputs({data, account, q})
|
||||
ignored = ignored.map(imports.stripemojis)
|
||||
only = only.map(imports.stripemojis)
|
||||
|
||||
@@ -20,12 +20,13 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
//Fetch star lists
|
||||
console.debug(`metrics/compute/${login}/plugins > starlists > fetching lists`)
|
||||
await page.goto(`https://github.com/${login}?tab=stars`)
|
||||
let lists = (await page.evaluate(login => [...document.querySelectorAll(`[href^='/stars/${login}/lists']`)].map(element => ({
|
||||
link:element.href,
|
||||
name:element.querySelector("h3")?.innerText ?? "",
|
||||
description:element.querySelector("span")?.innerText ?? "",
|
||||
count:Number(element.querySelector("div")?.innerText.match(/(?<count>\d+)/)?.groups.count),
|
||||
repositories:[],
|
||||
let lists = (await page.evaluate(login =>
|
||||
[...document.querySelectorAll(`[href^='/stars/${login}/lists']`)].map(element => ({
|
||||
link: element.href,
|
||||
name: element.querySelector("h3")?.innerText ?? "",
|
||||
description: element.querySelector("span")?.innerText ?? "",
|
||||
count: Number(element.querySelector("div")?.innerText.match(/(?<count>\d+)/)?.groups.count),
|
||||
repositories: [],
|
||||
})), login))
|
||||
const count = lists.length
|
||||
console.debug(`metrics/compute/${login}/plugins > starlists > found [${lists.map(({name}) => name)}]`)
|
||||
@@ -49,15 +50,16 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
console.debug(`metrics/compute/${login}/plugins > starlists > fetching page ${i}`)
|
||||
await page.goto(`${list.link}?page=${i}`)
|
||||
repositories.push(
|
||||
...await page.evaluate(() => [...document.querySelectorAll("#user-list-repositories > div:not(.paginate-container)")].map(element => ({
|
||||
name:element.querySelector("div:first-child")?.innerText.replace(" / ", "/") ?? "",
|
||||
description:element.querySelector(".py-1")?.innerText ?? "",
|
||||
language:{
|
||||
name:element.querySelector("[itemprop='programmingLanguage']")?.innerText ?? "",
|
||||
color:element.querySelector(".repo-language-color")?.style?.backgroundColor?.match(/\d+/g)?.map(x => Number(x).toString(16).padStart(2, "0")).join("") ?? null,
|
||||
...await page.evaluate(() =>
|
||||
[...document.querySelectorAll("#user-list-repositories > div:not(.paginate-container)")].map(element => ({
|
||||
name: element.querySelector("div:first-child")?.innerText.replace(" / ", "/") ?? "",
|
||||
description: element.querySelector(".py-1")?.innerText ?? "",
|
||||
language: {
|
||||
name: element.querySelector("[itemprop='programmingLanguage']")?.innerText ?? "",
|
||||
color: element.querySelector(".repo-language-color")?.style?.backgroundColor?.match(/\d+/g)?.map(x => Number(x).toString(16).padStart(2, "0")).join("") ?? null,
|
||||
},
|
||||
stargazers:Number(element.querySelector("[href$='/stargazers']")?.innerText.trim().replace(/[^\d]/g, "") ?? NaN),
|
||||
forks:Number(element.querySelector("[href$='/network/members']")?.innerText.trim().replace(/[^\d]/g, "") ?? NaN),
|
||||
stargazers: Number(element.querySelector("[href$='/stargazers']")?.innerText.trim().replace(/[^\d]/g, "") ?? NaN),
|
||||
forks: Number(element.querySelector("[href$='/network/members']")?.innerText.trim().replace(/[^\d]/g, "") ?? NaN),
|
||||
}))
|
||||
),
|
||||
)
|
||||
@@ -73,7 +75,7 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
//Compute languages statistics
|
||||
if (languages) {
|
||||
list.languages = {}
|
||||
for (const {language:{name, color}} of repositories) {
|
||||
for (const {language: {name, color}} of repositories) {
|
||||
if (name)
|
||||
list.languages[name] = (list.languages[name] ?? 0) + 1
|
||||
if (color)
|
||||
@@ -81,7 +83,7 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
}
|
||||
list.languages = Object.entries(list.languages).sort((a, b) => b[1] - a[1]).slice(0, _limit_languages || Infinity)
|
||||
const visible = list.languages.map(([_, value]) => value).reduce((a, b) => a + b, 0)
|
||||
list.languages = list.languages.map(([name, value]) => ({name, value, color:name in colors ? `#${colors[name]}` : null, x:0, p:value / visible}))
|
||||
list.languages = list.languages.map(([name, value]) => ({name, value, color: name in colors ? `#${colors[name]}` : null, x: 0, p: value / visible}))
|
||||
for (let i = 1; i < list.languages.length; i++)
|
||||
list.languages[i].x = (list.languages[i - 1]?.x ?? 0) + (list.languages[i - 1]?.value ?? 0) / visible
|
||||
}
|
||||
@@ -99,6 +101,6 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
}
|
||||
//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