Method for generating the contribution data
This commit is contained in:
parent
59d991d0a6
commit
9fbf6c541f
67
index.js
67
index.js
@ -71,3 +71,70 @@ async function initializeKredits () {
|
|||||||
return kredits;
|
return kredits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function generateContributionData(reviews, Contributor) {
|
||||||
|
const contributors = await Contributor.all();
|
||||||
|
|
||||||
|
const contributionData = {};
|
||||||
|
|
||||||
|
for (const [username, giteaReviews] of Object.entries(reviews.gitea)) {
|
||||||
|
const contributor = contributors.find(c => {
|
||||||
|
return c.gitea_username === username;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!contributor) {
|
||||||
|
console.log(`Could not find contributor for Gitea username ${username}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const urls = giteaReviews.map(review => review.pr.html_url);
|
||||||
|
const kreditsAmount = giteaReviews.reduce((amount, review) => {
|
||||||
|
return review.kredits + amount;
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
contributionData[contributor.name] = {
|
||||||
|
contributorId: contributor.id,
|
||||||
|
contributorIpfsHash: contributor.ipfsHash,
|
||||||
|
kind: 'dev',
|
||||||
|
amount: kreditsAmount,
|
||||||
|
description: 'PR reviews',
|
||||||
|
details: {
|
||||||
|
'pullRequests': urls
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [username, githubReviews] of Object.entries(reviews.github)) {
|
||||||
|
const contributor = contributors.find(c => {
|
||||||
|
return c.github_username === username;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!contributor) {
|
||||||
|
console.log(`Could not find contributor for Github username ${username}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const urls = githubReviews.map(review => review.pr.html_url);
|
||||||
|
const kreditsAmount = githubReviews.reduce((amount, review) => {
|
||||||
|
return review.kredits + amount;
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
if (typeof contributionData[contributor.name] !== 'undefined') {
|
||||||
|
contributionData[contributor.name].amount += kreditsAmount;
|
||||||
|
contributionData[contributor.name].details.pullRequests.push(...urls);
|
||||||
|
} else {
|
||||||
|
contributionData[contributor.name] = {
|
||||||
|
contributorId: contributor.id,
|
||||||
|
contributorIpfsHash: contributor.ipfsHash,
|
||||||
|
kind: 'dev',
|
||||||
|
amount: kreditsAmount,
|
||||||
|
description: 'PR reviews',
|
||||||
|
details: {
|
||||||
|
'pullRequests': urls
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return contributionData;
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user