Propose kredits for PR reviews #71
@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user