Propose kredits for PR reviews #71

Merged
raucao merged 5 commits from feature/review-kredits into master 2025-02-10 10:57:45 +00:00
Showing only changes of commit 5fd7e50893 - Show all commits

View File

@ -154,8 +154,12 @@ async function initializeKredits() {
async function generateContributionData(reviews, Contributor) { async function generateContributionData(reviews, Contributor) {
const contributors = await Contributor.all(); const contributors = await Contributor.all();
const contributionData = {}; const contributionData = {};
const now = new Date().toISOString().split('.')[0] + 'Z';
[date, time] = now.split('T'); const nextDay = new Date(endDate);
nextDay.setUTCDate(nextDay.getUTCDate() + 1);
nextDay.setUTCHours(0, 0, 0, 0);
const nextDayStr = nextDay.toISOString().split('.')[0] + 'Z';
[date, time] = nextDayStr.split('T');
function addContributionDataForPlatform(platform) { function addContributionDataForPlatform(platform) {
for (const [username, platformReviews] of Object.entries( for (const [username, platformReviews] of Object.entries(
@ -188,8 +192,8 @@ async function generateContributionData(reviews, Contributor) {
time, time,
amount: kreditsAmount, amount: kreditsAmount,
kind: 'dev', kind: 'dev',
description: `Pull request reviews (${argv.start} to ${argv.end})`,
details: { details: {
kind: 'review',
pullRequests: urls, pullRequests: urls,
}, },
}; };
@ -209,13 +213,32 @@ Promise.all([
]).then((values) => { ]).then((values) => {
const kredits = values[0]; const kredits = values[0];
const reviews = values[1]; const reviews = values[1];
const Contributor = kredits.Contributor;
const Contribution = kredits.Contribution;
generateContributionData(reviews, kredits.Contributor).then( function createContribution(nickname, attrs) {
(contributionData) => { console.log(`Creating review contribution for ${nickname}...`);
console.log(util.inspect(attrs, { depth: 1, colors: true }));
return Contribution.add(attrs).catch(error => {
console.error(`Error:`, error.message);
});
}
generateContributionData(reviews, Contributor).then(
async (contributionData) => {
if (argv.dry) { if (argv.dry) {
console.log('contributions:'); console.log('Contributions:');
console.log(util.inspect(contributionData, { depth: 3, colors: true })); console.log(util.inspect(contributionData, { depth: 3, colors: true }));
return; return;
} else {
for (const nickname of Object.keys(contributionData)) {
const description = `Reviewed ${contributionData[nickname].details.pullRequests.length} pull requests (from ${startDate.toISOString().split('T')[0]} to ${endDate.toISOString().split('T')[0]})`;
await createContribution(nickname, {
...contributionData[nickname],
description,
});
}
} }
} }
); );