Hi! Thanks for the action!
Is it possible to also add sponsors to the list?
- On one hand, we could do that only by also querying sponsors and adding them to the list.
- On the other hand, that might create some small conflict with #9, since we would now have to weight sponsors/contributors to put them in order. And I think #9 is crucial because contributions are likely to follow a Pareto distribution.
We can solve that issue with:
contributors.sort((a,b) => (a.contributions < b.contributions) ? 1 : -1);
If we were to have sponsors, then we'd have something like:
const sponsors_list = await octokit.request(`GET /repos/${owner}/sponsors`,{
// I could only find sponsors in the GraphQL API v4 though
// This is a bad example
headers: {
authorization: `token ${token}`,
},
})
// ...
const sponsors = sponsors_list.data.filter(el => el.type !== "Bot");
and then sort them with 100% preference for code contributions:
const everyone = contributors.concat(sponsors).sort(function (a, b){
const a_contributions = a.hasOwnProperty('contributions') ? a.contributions : 0;
const b_contributions = b.hasOwnProperty('contributions') ? b.contributions : 0;
if (a_contributions < b_contributions) {
return -1;
} else if (a.contributions > b.contributions) {
return +1;
} else {
// assuming sponsorship in a 'sponsorship' field
const a_value = a.hasOwnProperty('sponsorship') ? a.value : 0;
const b_value = b.hasOwnProperty('sponsorship') ? b.value : 0;
return (a_ sponsorship < b_ sponsorship) ? -1 : +1;
}
});
Or by providing weights:
const everyone = contributors.concat(sponsors).sort(function (a, b){
const a_contributions = a.hasOwnProperty('contributions') ? a.contributions : 0;
const b_contributions = b.hasOwnProperty('contributions') ? b.contributions : 0;
const a_ sponsorship = a.hasOwnProperty('sponsorship') ? a.value : 0;
const b_ sponsorship = b.hasOwnProperty('sponsorship') ? b.value : 0;
const a_score = a_contributions * contribution_weight + a_ sponsorship * sponsorship_weight;
const b_score = b_contributions * contribution_weight + b_ sponsorship * sponsorship_weight;
return (a_score < b_score) ? -1 : +1;
});
Because weights might be somewhat arbitrary, it could create normalized weights (from 0 to 1 for both) if the weights are not provided:
const max_contribution = Math.max.apply(Math, contributors.map(function(o) { return o.contributions; }))
const contribution_weight = 1./max_contribution;
const max_sponsorship = Math.max.apply(Math, contributors.map(function(o) { return o.sponsorship; }))
const sponsorship_weight = 1./max_sponsorship;
That should mix both in a less arbitrary way.
I can help with any of these things if you find the ideas useful.
Thanks,