Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(achievements): update total data acquisition method #1487

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions source/plugins/achievements/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,16 @@ async function total({imports}) {
//Extracting total from github.com/search
for (let i = 0; (i < 100) && ((!total.users) || (!total.repositories)); i++) {
const page = await browser.newPage()
await page.goto("https://github.com/search")
const result = await page.evaluate(() => [...document.querySelectorAll("h2")].filter(node => /Search more/.test(node.innerText)).shift()?.innerText.trim().match(/(?<count>\d+)M\s+(?<type>repositories|users|issues)$/)?.groups) ?? null
console.debug(`metrics/compute/plugins > achievements > setup found ${result?.type ?? "(?)"}`)
if ((result?.type) && (!total[result.type])) {
const {count, type} = result
total[type] = Number(count) * 10e5
console.debug(`metrics/compute/plugins > achievements > set total.${type} to ${total[type]}`)
await page.goto("https://github.com/search?q=+created%3A%3E2007")
const results = await page.evaluate(() => [...[...document.querySelectorAll("h2")].filter(node => /Filter by/.test(node.innerText)).shift()?.nextSibling?.innerText.trim().matchAll(/(?<type>Repositories|Users|Issues)\n(?<count>.*?)M/g) ?? []]) ?? null
for (const result of results) {
const type = result[1]?.toLowerCase()
console.debug(`metrics/compute/plugins > achievements > setup found ${type ?? "(?)"}`)
const count = result[2] ?? ""
if ((count !== "") && (!total[type])) {
total[type] = Number(count) * 10e5
console.debug(`metrics/compute/plugins > achievements > set total.${type} to ${total[type]}`)
}
}
await page.close()
await imports.wait(10 * Math.random())
Expand Down
Loading