fix(plugins/notable): plugin_notable_repositories not applied when plugin_notable_from: all (#679) [skip ci]

This commit is contained in:
Simon Lecoq
2021-11-26 03:07:29 +01:00
committed by GitHub
parent b26b679e3f
commit baebcb239a

View File

@@ -72,35 +72,32 @@ export default async function({login, q, imports, rest, graphql, data, account,
} }
//Aggregate contributions //Aggregate contributions
if (from !== "all") { console.debug(`metrics/compute/${login}/plugins > notable > aggregating results`)
console.debug(`metrics/compute/${login}/plugins > notable > aggregating results`) const aggregated = new Map()
contributions = contributions.filter(({organization}) => (from === "organization")&&(organization)) for (const {name, handle, avatar, organization = handle.split("/").shift() ?? "", stars, ..._extras} of contributions) {
const aggregated = new Map() const key = repositories ? handle : name
for (const {name, handle, avatar, organization, stars, ..._extras} of contributions) { if (aggregated.has(key)) {
const key = repositories ? handle : name const aggregate = aggregated.get(key)
if (aggregated.has(key)) { aggregate.aggregated++
const aggregate = aggregated.get(key) if (extras) {
aggregate.aggregated++ const {history = 0, user:{commits = 0, percentage = 0, maintainer = false} = {}} = _extras
if (extras) { aggregate.history = aggregate.history ?? 0
const {history = 0, user:{commits = 0, percentage = 0, maintainer = false} = {}} = _extras aggregate.history += history
aggregate.history = aggregate.history ?? 0 aggregate.user = aggregate.user ?? {}
aggregate.history += history aggregate.user.commits += commits
aggregate.user = aggregate.user ?? {} aggregate.user.percentage += percentage
aggregate.user.commits += commits aggregate.user.maintainer = aggregate.user.maintainer || maintainer
aggregate.user.percentage += percentage
aggregate.user.maintainer = aggregate.user.maintainer || maintainer
}
} }
else
aggregated.set(key, {name:key, handle, avatar, organization, stars, aggregated:1, ..._extras})
}
contributions = [...aggregated.values()]
if (extras) {
//Normalize contribution percentage
contributions.map(aggregate => aggregate.user ? aggregate.user.percentage /= aggregate.aggregated : null)
//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))
} }
else
aggregated.set(key, {name:key, handle, avatar, organization, stars, aggregated:1, ..._extras})
}
contributions = [...aggregated.values()]
if (extras) {
//Normalize contribution percentage
contributions.map(aggregate => aggregate.user ? aggregate.user.percentage /= aggregate.aggregated : null)
//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))
} }