Add basic support for organizations (#80)
This commit is contained in:
@@ -45,30 +45,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Query data from GitHub API
|
//Query data from GitHub API
|
||||||
console.debug(`metrics/compute/${login} > graphql query`)
|
await common({login, q, data, queries, repositories, graphql})
|
||||||
const forks = q["repositories.forks"] || false
|
|
||||||
Object.assign(data, await graphql(queries.common({login, "calendar.from":new Date(Date.now()-14*24*60*60*1000).toISOString(), "calendar.to":(new Date()).toISOString(), forks:forks ? "" : ", isFork: false"})))
|
|
||||||
//Query repositories from GitHub API
|
|
||||||
{
|
|
||||||
//Iterate through repositories
|
|
||||||
let cursor = null
|
|
||||||
let pushed = 0
|
|
||||||
do {
|
|
||||||
console.debug(`metrics/compute/${login} > retrieving repositories after ${cursor}`)
|
|
||||||
const {user:{repositories:{edges, nodes}}} = await graphql(queries.repositories({login, after:cursor ? `after: "${cursor}"` : "", repositories:Math.min(repositories, 100), forks:forks ? "" : ", isFork: false"}))
|
|
||||||
cursor = edges?.[edges?.length-1]?.cursor
|
|
||||||
data.user.repositories.nodes.push(...nodes)
|
|
||||||
pushed = nodes.length
|
|
||||||
} while ((pushed)&&(cursor)&&(data.user.repositories.nodes.length < repositories))
|
|
||||||
//Limit repositories
|
|
||||||
console.debug(`metrics/compute/${login} > keeping only ${repositories} repositories`)
|
|
||||||
data.user.repositories.nodes.splice(repositories)
|
|
||||||
console.debug(`metrics/compute/${login} > loaded ${data.user.repositories.nodes.length} repositories`)
|
|
||||||
}
|
|
||||||
//Compute metrics
|
//Compute metrics
|
||||||
console.debug(`metrics/compute/${login} > compute`)
|
console.debug(`metrics/compute/${login} > compute`)
|
||||||
const computer = Templates[template].default || Templates[template]
|
const computer = Templates[template].default || Templates[template]
|
||||||
await computer({login, q, dflags}, {conf, data, rest, graphql, plugins, queries}, {s, pending, imports:{plugins:Plugins, url, imgb64, axios, puppeteer, run, fs, os, paths, util, format, bytes, shuffle, htmlescape, urlexpand, __module}})
|
await computer({login, q, dflags}, {conf, data, rest, graphql, plugins, queries, account:data.account}, {s, pending, imports:{plugins:Plugins, url, imgb64, axios, puppeteer, run, fs, os, paths, util, format, bytes, shuffle, htmlescape, urlexpand, __module}})
|
||||||
const promised = await Promise.all(pending)
|
const promised = await Promise.all(pending)
|
||||||
|
|
||||||
//Check plugins errors
|
//Check plugins errors
|
||||||
@@ -123,6 +104,83 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Common query */
|
||||||
|
async function common({login, q, data, queries, repositories, graphql}) {
|
||||||
|
//Iterate through account types
|
||||||
|
for (const account of ["user", "organization"]) {
|
||||||
|
try {
|
||||||
|
//Query data from GitHub API
|
||||||
|
console.debug(`metrics/compute/${login}/common > account ${account}`)
|
||||||
|
const forks = q["repositories.forks"] || false
|
||||||
|
const queried = await graphql(queries[{user:"common", organization:"common.organization"}[account]]({login, "calendar.from":new Date(Date.now()-14*24*60*60*1000).toISOString(), "calendar.to":(new Date()).toISOString(), forks:forks ? "" : ", isFork: false"}))
|
||||||
|
Object.assign(data, {user:queried[account]})
|
||||||
|
common.post?.[account]({login, data})
|
||||||
|
//Query repositories from GitHub API
|
||||||
|
{
|
||||||
|
//Iterate through repositories
|
||||||
|
let cursor = null
|
||||||
|
let pushed = 0
|
||||||
|
do {
|
||||||
|
console.debug(`metrics/compute/${login}/common > retrieving repositories after ${cursor}`)
|
||||||
|
const {[account]:{repositories:{edges, nodes}}} = await graphql(queries.repositories({login, account, after:cursor ? `after: "${cursor}"` : "", repositories:Math.min(repositories, 100), forks:forks ? "" : ", isFork: false"}))
|
||||||
|
cursor = edges?.[edges?.length-1]?.cursor
|
||||||
|
data.user.repositories.nodes.push(...nodes)
|
||||||
|
pushed = nodes.length
|
||||||
|
} while ((pushed)&&(cursor)&&(data.user.repositories.nodes.length < repositories))
|
||||||
|
//Limit repositories
|
||||||
|
console.debug(`metrics/compute/${login}/common > keeping only ${repositories} repositories`)
|
||||||
|
data.user.repositories.nodes.splice(repositories)
|
||||||
|
console.debug(`metrics/compute/${login}/common > loaded ${data.user.repositories.nodes.length} repositories`)
|
||||||
|
}
|
||||||
|
//Success
|
||||||
|
console.debug(`metrics/compute/${login}/common > graphql query > account ${account} > success`)
|
||||||
|
return
|
||||||
|
} catch (error) {
|
||||||
|
console.debug(`metrics/compute/${login}/common > account ${account} > failed : ${error}`)
|
||||||
|
console.debug(`metrics/compute/${login}/common > checking next account`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Not found
|
||||||
|
console.debug(`metrics/compute/${login}/common > no more account type`)
|
||||||
|
throw new Error("user not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Common query post-processing */
|
||||||
|
common.post = {
|
||||||
|
//User
|
||||||
|
user({login, data}) {
|
||||||
|
console.debug(`metrics/compute/${login}/common > applying common post`)
|
||||||
|
data.account = "user"
|
||||||
|
Object.assign(data.user, {
|
||||||
|
isVerified:false,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
//Organization
|
||||||
|
organization({login, data}) {
|
||||||
|
console.debug(`metrics/compute/${login}/common > applying common post`)
|
||||||
|
data.account = "organization",
|
||||||
|
Object.assign(data.user, {
|
||||||
|
isHireable:false,
|
||||||
|
starredRepositories:{totalCount:0},
|
||||||
|
watching:{totalCount:0},
|
||||||
|
contributionsCollection:{
|
||||||
|
totalRepositoriesWithContributedCommits:0,
|
||||||
|
totalCommitContributions:0,
|
||||||
|
restrictedContributionsCount:0,
|
||||||
|
totalIssueContributions:0,
|
||||||
|
totalPullRequestContributions:0,
|
||||||
|
totalPullRequestReviewContributions:0,
|
||||||
|
},
|
||||||
|
calendar:{contributionCalendar:{weeks:[]}},
|
||||||
|
repositoriesContributedTo:{totalCount:0},
|
||||||
|
followers:{totalCount:0},
|
||||||
|
following:{totalCount:0},
|
||||||
|
issueComments:{totalCount:0},
|
||||||
|
organizations:{totalCount:0},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns module __dirname */
|
/** Returns module __dirname */
|
||||||
function __module(module) {
|
function __module(module) {
|
||||||
return paths.join(paths.dirname(url.fileURLToPath(module)))
|
return paths.join(paths.dirname(url.fileURLToPath(module)))
|
||||||
|
|||||||
@@ -167,7 +167,7 @@
|
|||||||
catch (error) {
|
catch (error) {
|
||||||
//Not found user
|
//Not found user
|
||||||
if ((error instanceof Error)&&(/^user not found$/.test(error.message))) {
|
if ((error instanceof Error)&&(/^user not found$/.test(error.message))) {
|
||||||
console.debug(`metrics/app/${login} > 404 (user not found)`)
|
console.debug(`metrics/app/${login} > 404 (user/organization not found)`)
|
||||||
return res.sendStatus(404)
|
return res.sendStatus(404)
|
||||||
}
|
}
|
||||||
//Invalid template
|
//Invalid template
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//Setup
|
//Setup
|
||||||
export default async function ({login, rest, imports, q}, {enabled = false} = {}) {
|
export default async function ({login, rest, q, account}, {enabled = false} = {}) {
|
||||||
//Plugin execution
|
//Plugin execution
|
||||||
try {
|
try {
|
||||||
//Check if plugin is enabled and requirements are met
|
//Check if plugin is enabled and requirements are met
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
console.debug(`metrics/compute/${login}/plugins > activity > ${events.length} events loaded`)
|
console.debug(`metrics/compute/${login}/plugins > activity > ${events.length} events loaded`)
|
||||||
//Extract activity events
|
//Extract activity events
|
||||||
const activity = events
|
const activity = events
|
||||||
.filter(({actor}) => actor.login === login)
|
.filter(({actor}) => account === "organization" ? true : actor.login === login)
|
||||||
.filter(({created_at}) => Number.isFinite(days) ? new Date(created_at) > new Date(Date.now()-days*24*60*60*1000) : true)
|
.filter(({created_at}) => Number.isFinite(days) ? new Date(created_at) > new Date(Date.now()-days*24*60*60*1000) : true)
|
||||||
.map(({type, payload, repo:{name:repo}}) => {
|
.map(({type, payload, repo:{name:repo}}) => {
|
||||||
//See https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/github-event-types
|
//See https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/github-event-types
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
//Setup
|
//Setup
|
||||||
export default async function ({login, graphql, q, queries}, {enabled = false} = {}) {
|
export default async function ({login, graphql, q, queries, account}, {enabled = false} = {}) {
|
||||||
//Plugin execution
|
//Plugin execution
|
||||||
try {
|
try {
|
||||||
//Check if plugin is enabled and requirements are met
|
//Check if plugin is enabled and requirements are met
|
||||||
if ((!enabled)||(!q.gists))
|
if ((!enabled)||(!q.gists))
|
||||||
return null
|
return null
|
||||||
|
if (account === "organization")
|
||||||
|
throw {error:{message:"Not available for organizations"}}
|
||||||
//Query gists from GitHub API
|
//Query gists from GitHub API
|
||||||
const gists = []
|
const gists = []
|
||||||
{
|
{
|
||||||
@@ -39,6 +41,8 @@
|
|||||||
}
|
}
|
||||||
//Handle errors
|
//Handle errors
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
if (error.error?.message)
|
||||||
|
throw error
|
||||||
throw {error:{message:"An error occured", instance:error}}
|
throw {error:{message:"An error occured", instance:error}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//Setup
|
//Setup
|
||||||
export default async function ({login, rest, imports, data, q}, {enabled = false, from:defaults = 100} = {}) {
|
export default async function ({login, rest, imports, data, q, account}, {enabled = false, from:defaults = 100} = {}) {
|
||||||
//Plugin execution
|
//Plugin execution
|
||||||
try {
|
try {
|
||||||
//Check if plugin is enabled and requirements are met
|
//Check if plugin is enabled and requirements are met
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
//Get user recent commits
|
//Get user recent commits
|
||||||
const commits = events
|
const commits = events
|
||||||
.filter(({type}) => type === "PushEvent")
|
.filter(({type}) => type === "PushEvent")
|
||||||
.filter(({actor}) => actor.login === login)
|
.filter(({actor}) => account === "organization" ? true : actor.login === login)
|
||||||
.filter(({created_at}) => new Date(created_at) > new Date(Date.now()-days*24*60*60*1000))
|
.filter(({created_at}) => new Date(created_at) > new Date(Date.now()-days*24*60*60*1000))
|
||||||
console.debug(`metrics/compute/${login}/plugins > habits > filtered out ${commits.length} push events over last ${days} days`)
|
console.debug(`metrics/compute/${login}/plugins > habits > filtered out ${commits.length} push events over last ${days} days`)
|
||||||
//Retrieve edited files and filter edited lines (those starting with +/-) from patches
|
//Retrieve edited files and filter edited lines (those starting with +/-) from patches
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
//Setup
|
//Setup
|
||||||
export default async function ({login, graphql, q, queries}, {enabled = false} = {}) {
|
export default async function ({login, graphql, q, queries, account}, {enabled = false} = {}) {
|
||||||
//Plugin execution
|
//Plugin execution
|
||||||
try {
|
try {
|
||||||
//Check if plugin is enabled and requirements are met
|
//Check if plugin is enabled and requirements are met
|
||||||
if ((!enabled)||(!q.isocalendar))
|
if ((!enabled)||(!q.isocalendar))
|
||||||
return null
|
return null
|
||||||
|
if (account === "organization")
|
||||||
|
throw {error:{message:"Not available for organizations"}}
|
||||||
//Parameters override
|
//Parameters override
|
||||||
let {"isocalendar.duration":duration = "half-year"} = q
|
let {"isocalendar.duration":duration = "half-year"} = q
|
||||||
//Duration in days
|
//Duration in days
|
||||||
@@ -83,6 +85,8 @@
|
|||||||
}
|
}
|
||||||
//Handle errors
|
//Handle errors
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
if (error.error?.message)
|
||||||
|
throw error
|
||||||
throw {error:{message:"An error occured", instance:error}}
|
throw {error:{message:"An error occured", instance:error}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,18 @@
|
|||||||
//Setup
|
//Setup
|
||||||
export default async function ({login, data, imports, rest, q}, {enabled = false} = {}) {
|
export default async function ({login, data, rest, q}, {enabled = false} = {}) {
|
||||||
//Plugin execution
|
//Plugin execution
|
||||||
try {
|
try {
|
||||||
//Check if plugin is enabled and requirements are met
|
//Check if plugin is enabled and requirements are met
|
||||||
if ((!enabled)||(!q.lines))
|
if ((!enabled)||(!q.lines))
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
//Context
|
||||||
|
let context = {mode:"user"}
|
||||||
|
if (q.repo) {
|
||||||
|
console.debug(`metrics/compute/${login}/plugins > people > switched to repository mode`)
|
||||||
|
context = {...context, mode:"repository"}
|
||||||
|
}
|
||||||
|
|
||||||
//Repositories
|
//Repositories
|
||||||
const repositories = data.user.repositories.nodes.map(({name:repo, owner:{login:owner}}) => ({repo, owner})) ?? []
|
const repositories = data.user.repositories.nodes.map(({name:repo, owner:{login:owner}}) => ({repo, owner})) ?? []
|
||||||
//Get contributors stats from repositories
|
//Get contributors stats from repositories
|
||||||
@@ -18,7 +26,7 @@
|
|||||||
if (!Array.isArray(repository))
|
if (!Array.isArray(repository))
|
||||||
return
|
return
|
||||||
//Extract author
|
//Extract author
|
||||||
const [contributor] = repository.filter(({author}) => author.login === login)
|
const [contributor] = repository.filter(({author}) => context.mode === "repository" ? true : author.login === login)
|
||||||
//Compute editions
|
//Compute editions
|
||||||
if (contributor)
|
if (contributor)
|
||||||
contributor.weeks.forEach(({a, d}) => (lines.added += a, lines.deleted += d))
|
contributor.weeks.forEach(({a, d}) => (lines.added += a, lines.deleted += d))
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//Setup
|
//Setup
|
||||||
export default async function ({login, data, graphql, rest, q, queries, imports}, {enabled = false} = {}) {
|
export default async function ({login, data, graphql, rest, q, queries, imports, account}, {enabled = false} = {}) {
|
||||||
//Plugin execution
|
//Plugin execution
|
||||||
try {
|
try {
|
||||||
//Check if plugin is enabled and requirements are met
|
//Check if plugin is enabled and requirements are met
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
//Context
|
//Context
|
||||||
let context = {
|
let context = {
|
||||||
mode:"user",
|
mode:"user",
|
||||||
types:["followers", "following", "sponsorshipsAsMaintainer", "sponsorshipsAsSponsor", "thanks"],
|
types:account === "organization" ? ["sponsorshipsAsMaintainer", "sponsorshipsAsSponsor", "thanks"] : ["followers", "following", "sponsorshipsAsMaintainer", "sponsorshipsAsSponsor", "thanks"],
|
||||||
default:"followers, following",
|
default:"followers, following",
|
||||||
alias:{followed:"following", sponsors:"sponsorshipsAsMaintainer", sponsored:"sponsorshipsAsSponsor", sponsoring:"sponsorshipsAsSponsor"},
|
alias:{followed:"following", sponsors:"sponsorshipsAsMaintainer", sponsored:"sponsorshipsAsSponsor", sponsoring:"sponsorshipsAsSponsor"},
|
||||||
sponsorships:{sponsorshipsAsMaintainer:"sponsorEntity", sponsorshipsAsSponsor:"sponsorable"}
|
sponsorships:{sponsorshipsAsMaintainer:"sponsorEntity", sponsorshipsAsSponsor:"sponsorable"}
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
if (q.repo) {
|
if (q.repo) {
|
||||||
console.debug(`metrics/compute/${login}/plugins > people > switched to repository mode`)
|
console.debug(`metrics/compute/${login}/plugins > people > switched to repository mode`)
|
||||||
const {owner, repo} = data.user.repositories.nodes.map(({name:repo, owner:{login:owner}}) => ({repo, owner})).shift()
|
const {owner, repo} = data.user.repositories.nodes.map(({name:repo, owner:{login:owner}}) => ({repo, owner})).shift()
|
||||||
context = {...context, mode:"repo", types:["contributors", "stargazers", "watchers", "sponsorshipsAsMaintainer", "thanks"], default:"stargazers, watchers", owner, repo}
|
context = {...context, mode:"repository", types:["contributors", "stargazers", "watchers", "sponsorshipsAsMaintainer", "thanks"], default:"stargazers, watchers", owner, repo}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Parameters override
|
//Parameters override
|
||||||
@@ -52,8 +52,8 @@
|
|||||||
do {
|
do {
|
||||||
console.debug(`metrics/compute/${login}/plugins > people > retrieving ${type} after ${cursor}`)
|
console.debug(`metrics/compute/${login}/plugins > people > retrieving ${type} after ${cursor}`)
|
||||||
const {[type]:{edges}} = (
|
const {[type]:{edges}} = (
|
||||||
type in context.sponsorships ? (await graphql(queries["people.sponsors"]({login:context.owner ?? login, type, size, after:cursor ? `after: "${cursor}"` : "", target:context.sponsorships[type]}))).user :
|
type in context.sponsorships ? (await graphql(queries["people.sponsors"]({login:context.owner ?? login, type, size, after:cursor ? `after: "${cursor}"` : "", target:context.sponsorships[type], account})))[account] :
|
||||||
context.mode === "repo" ? (await graphql(queries["people.repository"]({login:context.owner, repository:context.repo, type, size, after:cursor ? `after: "${cursor}"` : ""}))).user.repository :
|
context.mode === "repository" ? (await graphql(queries["people.repository"]({login:context.owner, repository:context.repo, type, size, after:cursor ? `after: "${cursor}"` : "", account})))[account].repository :
|
||||||
(await graphql(queries.people({login, type, size, after:cursor ? `after: "${cursor}"` : ""}))).user
|
(await graphql(queries.people({login, type, size, after:cursor ? `after: "${cursor}"` : ""}))).user
|
||||||
)
|
)
|
||||||
cursor = edges?.[edges?.length-1]?.cursor
|
cursor = edges?.[edges?.length-1]?.cursor
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//Setup
|
//Setup
|
||||||
export default async function ({login, graphql, q, queries}, {enabled = false} = {}) {
|
export default async function ({login, graphql, q, queries, account}, {enabled = false} = {}) {
|
||||||
//Plugin execution
|
//Plugin execution
|
||||||
try {
|
try {
|
||||||
//Check if plugin is enabled and requirements are met
|
//Check if plugin is enabled and requirements are met
|
||||||
@@ -13,13 +13,13 @@
|
|||||||
limit = Math.max(repositories.length, Math.min(100, Number(limit)))
|
limit = Math.max(repositories.length, Math.min(100, Number(limit)))
|
||||||
//Retrieve user owned projects from graphql api
|
//Retrieve user owned projects from graphql api
|
||||||
console.debug(`metrics/compute/${login}/plugins > projects > querying api`)
|
console.debug(`metrics/compute/${login}/plugins > projects > querying api`)
|
||||||
const {user:{projects}} = await graphql(queries.projects({login, limit}))
|
const {[account]:{projects}} = await graphql(queries.projects({login, limit, account}))
|
||||||
//Retrieve repositories projects from graphql api
|
//Retrieve repositories projects from graphql api
|
||||||
for (const identifier of repositories) {
|
for (const identifier of repositories) {
|
||||||
//Querying repository project
|
//Querying repository project
|
||||||
console.debug(`metrics/compute/${login}/plugins > projects > querying api for ${identifier}`)
|
console.debug(`metrics/compute/${login}/plugins > projects > querying api for ${identifier}`)
|
||||||
const {user, repository, id} = identifier.match(/(?<user>[-\w]+)[/](?<repository>[-\w]+)[/]projects[/](?<id>\d+)/)?.groups
|
const {user, repository, id} = identifier.match(/(?<user>[-\w]+)[/](?<repository>[-\w]+)[/]projects[/](?<id>\d+)/)?.groups
|
||||||
const {user:{repository:{project}}} = await graphql(queries["projects.repository"]({user, repository, id}))
|
const {[account]:{repository:{project}}} = await graphql(queries["projects.repository"]({user, repository, id, account}))
|
||||||
//Adding it to projects list
|
//Adding it to projects list
|
||||||
console.debug(`metrics/compute/${login}/plugins > projects > registering ${identifier}`)
|
console.debug(`metrics/compute/${login}/plugins > projects > registering ${identifier}`)
|
||||||
project.name = `${project.name} (${user}/${repository})`
|
project.name = `${project.name} (${user}/${repository})`
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//Setup
|
//Setup
|
||||||
export default async function ({login, graphql, data, q, queries, imports}, {enabled = false} = {}) {
|
export default async function ({login, graphql, data, q, queries}, {enabled = false} = {}) {
|
||||||
//Plugin execution
|
//Plugin execution
|
||||||
try {
|
try {
|
||||||
//Check if plugin is enabled and requirements are met
|
//Check if plugin is enabled and requirements are met
|
||||||
@@ -7,16 +7,16 @@
|
|||||||
return null
|
return null
|
||||||
//Retrieve stargazers from graphql api
|
//Retrieve stargazers from graphql api
|
||||||
console.debug(`metrics/compute/${login}/plugins > stargazers > querying api`)
|
console.debug(`metrics/compute/${login}/plugins > stargazers > querying api`)
|
||||||
const repositories = data.user.repositories.nodes.map(({name}) => name).slice(0, 2)
|
const repositories = data.user.repositories.nodes.map(({name:repository, owner:{login:owner}}) => ({repository, owner})) ?? []
|
||||||
const dates = []
|
const dates = []
|
||||||
for (const repository of repositories) {
|
for (const {repository, owner} of repositories) {
|
||||||
//Iterate through stargazers
|
//Iterate through stargazers
|
||||||
console.debug(`metrics/compute/${login}/plugins > stargazers > retrieving stargazers of ${repository}`)
|
console.debug(`metrics/compute/${login}/plugins > stargazers > retrieving stargazers of ${repository}`)
|
||||||
let cursor = null
|
let cursor = null
|
||||||
let pushed = 0
|
let pushed = 0
|
||||||
do {
|
do {
|
||||||
console.debug(`metrics/compute/${login}/plugins > stargazers > retrieving stargazers of ${repository} after ${cursor}`)
|
console.debug(`metrics/compute/${login}/plugins > stargazers > retrieving stargazers of ${repository} after ${cursor}`)
|
||||||
const {repository:{stargazers:{edges}}} = await graphql(queries.stargazers({login, repository, after:cursor ? `after: "${cursor}"` : ""}))
|
const {repository:{stargazers:{edges}}} = await graphql(queries.stargazers({login:owner, repository, after:cursor ? `after: "${cursor}"` : ""}))
|
||||||
cursor = edges?.[edges?.length-1]?.cursor
|
cursor = edges?.[edges?.length-1]?.cursor
|
||||||
dates.push(...edges.map(({starredAt}) => new Date(starredAt)))
|
dates.push(...edges.map(({starredAt}) => new Date(starredAt)))
|
||||||
pushed = edges.length
|
pushed = edges.length
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
//Setup
|
//Setup
|
||||||
export default async function ({login, graphql, q, queries, imports}, {enabled = false} = {}) {
|
export default async function ({login, graphql, q, queries, account}, {enabled = false} = {}) {
|
||||||
//Plugin execution
|
//Plugin execution
|
||||||
try {
|
try {
|
||||||
//Check if plugin is enabled and requirements are met
|
//Check if plugin is enabled and requirements are met
|
||||||
if ((!enabled)||(!q.stars))
|
if ((!enabled)||(!q.stars))
|
||||||
return null
|
return null
|
||||||
|
if (account === "organization")
|
||||||
|
throw {error:{message:"Not available for organizations"}}
|
||||||
//Parameters override
|
//Parameters override
|
||||||
let {"stars.limit":limit = 4} = q
|
let {"stars.limit":limit = 4} = q
|
||||||
//Limit
|
//Limit
|
||||||
@@ -28,6 +30,8 @@
|
|||||||
}
|
}
|
||||||
//Handle errors
|
//Handle errors
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
if (error.error?.message)
|
||||||
|
throw error
|
||||||
throw {error:{message:"An error occured", instance:error}}
|
throw {error:{message:"An error occured", instance:error}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
//Setup
|
//Setup
|
||||||
export default async function ({login, imports, q}, {enabled = false} = {}) {
|
export default async function ({login, imports, q, account}, {enabled = false} = {}) {
|
||||||
//Plugin execution
|
//Plugin execution
|
||||||
try {
|
try {
|
||||||
//Check if plugin is enabled and requirements are met
|
//Check if plugin is enabled and requirements are met
|
||||||
if ((!enabled)||(!q.topics))
|
if ((!enabled)||(!q.topics))
|
||||||
return null
|
return null
|
||||||
|
if (account === "organization")
|
||||||
|
throw {error:{message:"Not available for organizations"}}
|
||||||
//Parameters override
|
//Parameters override
|
||||||
let {"topics.sort":sort = "stars", "topics.mode":mode = "starred", "topics.limit":limit} = q
|
let {"topics.sort":sort = "stars", "topics.mode":mode = "starred", "topics.limit":limit} = q
|
||||||
//Shuffle
|
//Shuffle
|
||||||
@@ -85,6 +87,8 @@
|
|||||||
}
|
}
|
||||||
//Handle errors
|
//Handle errors
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
if (error.error?.message)
|
||||||
|
throw error
|
||||||
throw {error:{message:"An error occured", instance:error}}
|
throw {error:{message:"An error occured", instance:error}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
29
source/queries/common.organization.graphql
Normal file
29
source/queries/common.organization.graphql
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
query MetricsOrganization {
|
||||||
|
organization(login: "$login") {
|
||||||
|
databaseId
|
||||||
|
name
|
||||||
|
login
|
||||||
|
createdAt
|
||||||
|
avatarUrl
|
||||||
|
websiteUrl
|
||||||
|
isVerified
|
||||||
|
twitterUsername
|
||||||
|
repositories(last: 0) {
|
||||||
|
totalCount
|
||||||
|
totalDiskUsage
|
||||||
|
nodes {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
packages {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
sponsorshipsAsSponsor {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
sponsorshipsAsMaintainer {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
query PeopleRepository {
|
query PeopleRepository {
|
||||||
user(login: "$login") {
|
$account(login: "$login") {
|
||||||
repository(name: "$repository") {
|
repository(name: "$repository") {
|
||||||
$type($after first: 100) {
|
$type($after first: 100) {
|
||||||
edges {
|
edges {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
query PeopleSponsors {
|
query PeopleSponsors {
|
||||||
user(login: "$login") {
|
$account(login: "$login") {
|
||||||
login
|
login
|
||||||
$type($after first: 100) {
|
$type($after first: 100) {
|
||||||
edges {
|
edges {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
query Projects {
|
query Projects {
|
||||||
user(login: "$login") {
|
$account(login: "$login") {
|
||||||
projects(last: $limit, states: OPEN, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
projects(last: $limit, states: OPEN, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
||||||
totalCount
|
totalCount
|
||||||
nodes {
|
nodes {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
query RepositoryProject {
|
query RepositoryProject {
|
||||||
user(login: "$user") {
|
$account(login: "$user") {
|
||||||
repository(name: "$repository") {
|
repository(name: "$repository") {
|
||||||
project(number: $id) {
|
project(number: $id) {
|
||||||
name
|
name
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
query Repositories {
|
query Repositories {
|
||||||
user(login: "$login") {
|
$account(login: "$login") {
|
||||||
repositories($after first: $repositories $forks, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
repositories($after first: $repositories $forks, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
||||||
edges {
|
edges {
|
||||||
cursor
|
cursor
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
query Repository {
|
query Repository {
|
||||||
user(login: "$login") {
|
$account(login: "$login") {
|
||||||
repository(name: "$repo") {
|
repository(name: "$repo") {
|
||||||
name
|
name
|
||||||
owner {
|
owner {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/** Template common processor */
|
/** 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
|
//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}}
|
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 () => {
|
pending.push((async () => {
|
||||||
try {
|
try {
|
||||||
console.debug(`metrics/compute/${login}/plugins > ${name} > started`)
|
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`)
|
console.debug(`metrics/compute/${login}/plugins > ${name} > completed`)
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import common from "./../common.mjs"
|
import common from "./../common.mjs"
|
||||||
|
|
||||||
/** Template processor */
|
/** 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
|
//Check arguments
|
||||||
const {repo} = q
|
const {repo} = q
|
||||||
if (!repo) {
|
if (!repo) {
|
||||||
@@ -10,10 +10,11 @@
|
|||||||
data.errors.push({error:{message:`You must pass a "repo" argument to use this template`}})
|
data.errors.push({error:{message:`You must pass a "repo" argument to use this template`}})
|
||||||
return await common(...arguments)
|
return await common(...arguments)
|
||||||
}
|
}
|
||||||
|
console.debug(`metrics/compute/${login}/${repo} > switching to mode ${account}`)
|
||||||
|
|
||||||
//Retrieving single repository
|
//Retrieving single repository
|
||||||
console.debug(`metrics/compute/${login}/${repo} > retrieving single repository ${repo}`)
|
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.user.repositories.nodes = [repository]
|
||||||
data.repo = repository
|
data.repo = repository
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@
|
|||||||
const commits = []
|
const commits = []
|
||||||
for (let page = 0; page < 100; page++) {
|
for (let page = 0; page < 100; page++) {
|
||||||
console.debug(`metrics/compute/${login}/${repo} > loading page ${page}`)
|
console.debug(`metrics/compute/${login}/${repo} > loading page ${page}`)
|
||||||
|
try {
|
||||||
const {data} = await rest.repos.listCommits({owner:login, repo, per_page:100, page})
|
const {data} = await rest.repos.listCommits({owner:login, repo, per_page:100, page})
|
||||||
if (!data.length) {
|
if (!data.length) {
|
||||||
console.debug(`metrics/compute/${login}/${repo} > no more page to load`)
|
console.debug(`metrics/compute/${login}/${repo} > no more page to load`)
|
||||||
@@ -33,6 +35,12 @@
|
|||||||
}
|
}
|
||||||
commits.push(...data)
|
commits.push(...data)
|
||||||
}
|
}
|
||||||
|
catch (error) {
|
||||||
|
if (/Git Repository is empty/.test(error))
|
||||||
|
break
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
console.debug(`metrics/compute/${login}/${repo} > ${commits.length} commits loaded`)
|
console.debug(`metrics/compute/${login}/${repo} > ${commits.length} commits loaded`)
|
||||||
|
|
||||||
//Override creation date, disk usage and website url
|
//Override creation date, disk usage and website url
|
||||||
|
|||||||
Reference in New Issue
Block a user