Refactor to remove some duplications
This commit is contained in:
parent
bffaae064c
commit
8d15f69c75
78
index.js
78
index.js
@ -76,65 +76,43 @@ async function generateContributionData(reviews, Contributor) {
|
||||
|
||||
const contributionData = {};
|
||||
|
||||
for (const [username, giteaReviews] of Object.entries(reviews.gitea)) {
|
||||
const contributor = contributors.find(c => {
|
||||
return c.gitea_username === username;
|
||||
});
|
||||
function addContributionDataForPlatform(platform) {
|
||||
for (const [username, platformReviews] of Object.entries(reviews[platform])) {
|
||||
const contributor = contributors.find(c => {
|
||||
return c[`${platform}_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
|
||||
if (!contributor) {
|
||||
console.log(`Could not find contributor for ${platform} user "${username}"`);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const [username, githubReviews] of Object.entries(reviews.github)) {
|
||||
const contributor = contributors.find(c => {
|
||||
return c.github_username === username;
|
||||
});
|
||||
const urls = platformReviews.map(review => review.pr.html_url);
|
||||
const kreditsAmount = platformReviews.reduce((amount, review) => {
|
||||
return review.kredits + amount;
|
||||
}, 0);
|
||||
|
||||
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
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addContributionDataForPlatform('gitea');
|
||||
addContributionDataForPlatform('github');
|
||||
|
||||
return contributionData;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user