fix(plugins/lines): add support for organization history (#1356)

This commit is contained in:
Simon Lecoq
2023-01-16 20:13:05 -05:00
committed by GitHub
parent d418264c77
commit e015fac116
2 changed files with 7 additions and 3 deletions

View File

@@ -12,13 +12,16 @@ export default async function({login, data, imports, rest, q, account}, {enabled
//Context
let context = {mode: "user"}
if (q.repo) {
if (data.account) {
context = {...context, mode: "organization"}
}
else if (q.repo) {
console.debug(`metrics/compute/${login}/plugins > people > switched to repository mode`)
context = {...context, mode: "repository"}
}
//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})).sort((a, b) => new Date(b.updatedAt) - new Date(a.updatedAt)) ?? []
//Get contributors stats from repositories
console.debug(`metrics/compute/${login}/plugins > lines > querying api`)
@@ -35,7 +38,7 @@ export default async function({login, data, imports, rest, q, account}, {enabled
return
//Compute changes
repos[handle] = {added: 0, deleted: 0, changed: 0}
const contributors = stats.filter(({author}) => context.mode === "repository" ? true : author?.login?.toLocaleLowerCase() === login.toLocaleLowerCase())
const contributors = stats.filter(({author}) => (context.mode === "repository")||(context.mode === "organization") ? true : author?.login?.toLocaleLowerCase() === login.toLocaleLowerCase())
for (const contributor of contributors) {
let added = 0, changed = 0, deleted = 0
contributor.weeks.forEach(({a = 0, d = 0, c = 0, w}) => {