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 = {};
|
const contributionData = {};
|
||||||
|
|
||||||
for (const [username, giteaReviews] of Object.entries(reviews.gitea)) {
|
function addContributionDataForPlatform(platform) {
|
||||||
const contributor = contributors.find(c => {
|
for (const [username, platformReviews] of Object.entries(reviews[platform])) {
|
||||||
return c.gitea_username === username;
|
const contributor = contributors.find(c => {
|
||||||
});
|
return c[`${platform}_username`] === username;
|
||||||
|
});
|
||||||
|
|
||||||
if (!contributor) {
|
if (!contributor) {
|
||||||
console.log(`Could not find contributor for Gitea username ${username}`);
|
console.log(`Could not find contributor for ${platform} user "${username}"`);
|
||||||
continue;
|
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 urls = platformReviews.map(review => review.pr.html_url);
|
||||||
const contributor = contributors.find(c => {
|
const kreditsAmount = platformReviews.reduce((amount, review) => {
|
||||||
return c.github_username === username;
|
return review.kredits + amount;
|
||||||
});
|
}, 0);
|
||||||
|
|
||||||
if (!contributor) {
|
if (typeof contributionData[contributor.name] !== 'undefined') {
|
||||||
console.log(`Could not find contributor for Github username ${username}`);
|
contributionData[contributor.name].amount += kreditsAmount;
|
||||||
continue;
|
contributionData[contributor.name].details.pullRequests.push(...urls);
|
||||||
}
|
} else {
|
||||||
|
contributionData[contributor.name] = {
|
||||||
const urls = githubReviews.map(review => review.pr.html_url);
|
contributorId: contributor.id,
|
||||||
const kreditsAmount = githubReviews.reduce((amount, review) => {
|
contributorIpfsHash: contributor.ipfsHash,
|
||||||
return review.kredits + amount;
|
kind: 'dev',
|
||||||
}, 0);
|
amount: kreditsAmount,
|
||||||
|
description: 'PR reviews',
|
||||||
if (typeof contributionData[contributor.name] !== 'undefined') {
|
details: {
|
||||||
contributionData[contributor.name].amount += kreditsAmount;
|
'pullRequests': urls
|
||||||
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;
|
return contributionData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user