Create contributions for reviews

* Improve the description to include number of PRs and start/end date
* Set the contribution date to 00:00 on the day after the end date
* Add a sub-kind to the details property so it's easy to identify
  reviews
This commit is contained in:
Râu Cao 2025-02-09 12:55:27 +04:00
parent c93ddaebee
commit 5fd7e50893
Signed by: raucao
GPG Key ID: 37036C356E56CC51

View File

@ -154,8 +154,12 @@ async function initializeKredits() {
async function generateContributionData(reviews, Contributor) {
const contributors = await Contributor.all();
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) {
for (const [username, platformReviews] of Object.entries(
@ -188,8 +192,8 @@ async function generateContributionData(reviews, Contributor) {
time,
amount: kreditsAmount,
kind: 'dev',
description: `Pull request reviews (${argv.start} to ${argv.end})`,
details: {
kind: 'review',
pullRequests: urls,
},
};
@ -209,13 +213,32 @@ Promise.all([
]).then((values) => {
const kredits = values[0];
const reviews = values[1];
const Contributor = kredits.Contributor;
const Contribution = kredits.Contribution;
generateContributionData(reviews, kredits.Contributor).then(
(contributionData) => {
function createContribution(nickname, attrs) {
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) {
console.log('contributions:');
console.log('Contributions:');
console.log(util.inspect(contributionData, { depth: 3, colors: true }));
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,
});
}
}
}
);