feat(plugins/notables): advanced filters (#789)

This commit is contained in:
Simon Lecoq
2022-01-19 14:24:33 +01:00
committed by GitHub
parent a7079285f3
commit 3df178d997
3 changed files with 30 additions and 5 deletions

View File

@@ -7,7 +7,8 @@ export default async function({login, q, imports, rest, graphql, data, account,
return null
//Load inputs
let {filter, repositories, from, indepth} = imports.metadata.plugins.notable.inputs({data, account, q})
let {filter, skipped, repositories, from, indepth} = imports.metadata.plugins.notable.inputs({data, account, q})
skipped.push(...data.shared["repositories.skipped"])
//Iterate through contributed repositories
const commits = []
@@ -19,6 +20,7 @@ export default async function({login, q, imports, rest, graphql, data, account,
const {user:{repositoriesContributedTo:{edges}}} = await graphql(queries.notable.contributions({login, after:cursor ? `after: "${cursor}"` : "", repositories:data.shared["repositories.batch"] || 100}))
cursor = edges?.[edges?.length - 1]?.cursor
edges
.filter(({node}) => !((skipped.includes(node.nameWithOwner.toLocaleLowerCase()))||(skipped.includes(node.nameWithOwner.split("/")[1].toLocaleLowerCase()))))
.filter(({node}) => ({all:true, organization:node.isInOrganization, user:!node.isInOrganization}[from]))
.filter(({node}) => imports.ghfilter(filter, {name:node.nameWithOwner, user:node.owner.login, stars:node.stargazers.totalCount, watchers:node.watchers.totalCount, forks:node.forks.totalCount}))
.map(({node}) => commits.push({handle:node.nameWithOwner, stars:node.stargazers.totalCount, organization:node.isInOrganization, avatarUrl:node.owner.avatarUrl}))
@@ -79,7 +81,7 @@ export default async function({login, q, imports, rest, graphql, data, account,
if (aggregated.has(key)) {
const aggregate = aggregated.get(key)
aggregate.aggregated++
if (extras) {
if (indepth) {
const {history = 0, user:{commits = 0, percentage = 0, maintainer = false} = {}} = _extras
aggregate.history = aggregate.history ?? 0
aggregate.history += history
@@ -94,9 +96,11 @@ export default async function({login, q, imports, rest, graphql, data, account,
}
contributions = [...aggregated.values()]
if (extras) {
if (indepth) {
//Normalize contribution percentage
contributions.map(aggregate => aggregate.user ? aggregate.user.percentage /= aggregate.aggregated : null)
//Additional filtering (no user commits means that API wasn't able to answer back, considering it as matching by default)
contributions = contributions.filter(({handle, user}) => !user?.commits ? true : imports.ghfilter(filter, {handle, commits:contributions.history, "commits.user":user.commits, "commits.user%":user.percentage*100, maintainer:user.maintainer}))
//Sort contribution by maintainer first and then by contribution percentage
contributions = contributions.sort((a, b) => ((b.user?.percentage + b.user?.maintainer) || 0) - ((a.user?.percentage + a.user?.maintainer) || 0))
}