Skip to content

Commit e015fac

Browse files
authored
fix(plugins/lines): add support for organization history (lowlighter#1356)
1 parent d418264 commit e015fac

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

source/plugins/base/queries/repositories.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ query BaseRepositories {
55
cursor
66
}
77
nodes {
8+
updatedAt
89
name
910
owner {
1011
login

source/plugins/lines/index.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ export default async function({login, data, imports, rest, q, account}, {enabled
1212

1313
//Context
1414
let context = {mode: "user"}
15-
if (q.repo) {
15+
if (data.account) {
16+
context = {...context, mode: "organization"}
17+
}
18+
else if (q.repo) {
1619
console.debug(`metrics/compute/${login}/plugins > people > switched to repository mode`)
1720
context = {...context, mode: "repository"}
1821
}
1922

2023
//Repositories
21-
const repositories = data.user.repositories.nodes.map(({name: repo, owner: {login: owner}}) => ({repo, owner})) ?? []
24+
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)) ?? []
2225

2326
//Get contributors stats from repositories
2427
console.debug(`metrics/compute/${login}/plugins > lines > querying api`)
@@ -35,7 +38,7 @@ export default async function({login, data, imports, rest, q, account}, {enabled
3538
return
3639
//Compute changes
3740
repos[handle] = {added: 0, deleted: 0, changed: 0}
38-
const contributors = stats.filter(({author}) => context.mode === "repository" ? true : author?.login?.toLocaleLowerCase() === login.toLocaleLowerCase())
41+
const contributors = stats.filter(({author}) => (context.mode === "repository")||(context.mode === "organization") ? true : author?.login?.toLocaleLowerCase() === login.toLocaleLowerCase())
3942
for (const contributor of contributors) {
4043
let added = 0, changed = 0, deleted = 0
4144
contributor.weeks.forEach(({a = 0, d = 0, c = 0, w}) => {

0 commit comments

Comments
 (0)