Add basic support for organizations (#80)

This commit is contained in:
Simon Lecoq
2021-01-25 23:47:24 +01:00
committed by GitHub
parent d4d873bb39
commit 1c8dcbc8aa
21 changed files with 178 additions and 59 deletions

View File

@@ -1,5 +1,5 @@
/** Template common processor */
export default async function ({login, q, dflags}, {conf, data, rest, graphql, plugins, queries}, {s, pending, imports}) {
export default async function ({login, q, dflags}, {conf, data, rest, graphql, plugins, queries, account}, {s, pending, imports}) {
//Init
const computed = data.computed = {commits:0, sponsorships:0, licenses:{favorite:"", used:{}}, token:{}, repositories:{watchers:0, stargazers:0, issues_open:0, issues_closed:0, pr_open:0, pr_merged:0, forks:0, forked:0, releases:0}}
@@ -32,7 +32,7 @@
pending.push((async () => {
try {
console.debug(`metrics/compute/${login}/plugins > ${name} > started`)
data.plugins[name] = await imports.plugins[name]({login, q, imports, data, computed, rest, graphql, queries}, plugins[name])
data.plugins[name] = await imports.plugins[name]({login, q, imports, data, computed, rest, graphql, queries, account}, plugins[name])
console.debug(`metrics/compute/${login}/plugins > ${name} > completed`)
}
catch (error) {

View File

@@ -2,7 +2,7 @@
import common from "./../common.mjs"
/** Template processor */
export default async function ({login, q}, {conf, data, rest, graphql, plugins, queries}, {s, pending, imports}) {
export default async function ({login, q}, {conf, data, rest, graphql, plugins, queries, account}, {s, pending, imports}) {
//Check arguments
const {repo} = q
if (!repo) {
@@ -10,10 +10,11 @@
data.errors.push({error:{message:`You must pass a "repo" argument to use this template`}})
return await common(...arguments)
}
console.debug(`metrics/compute/${login}/${repo} > switching to mode ${account}`)
//Retrieving single repository
console.debug(`metrics/compute/${login}/${repo} > retrieving single repository ${repo}`)
const {user:{repository}} = await graphql(queries.repository({login, repo}))
const {[account]:{repository}} = await graphql(queries.repository({login, repo, account}))
data.user.repositories.nodes = [repository]
data.repo = repository
@@ -26,12 +27,19 @@
const commits = []
for (let page = 0; page < 100; page++) {
console.debug(`metrics/compute/${login}/${repo} > loading page ${page}`)
const {data} = await rest.repos.listCommits({owner:login, repo, per_page:100, page})
if (!data.length) {
console.debug(`metrics/compute/${login}/${repo} > no more page to load`)
break
try {
const {data} = await rest.repos.listCommits({owner:login, repo, per_page:100, page})
if (!data.length) {
console.debug(`metrics/compute/${login}/${repo} > no more page to load`)
break
}
commits.push(...data)
}
catch (error) {
if (/Git Repository is empty/.test(error))
break
throw error
}
commits.push(...data)
}
console.debug(`metrics/compute/${login}/${repo} > ${commits.length} commits loaded`)