Add prettier config

This commit is contained in:
galfert 2023-02-26 22:49:11 +01:00
parent a5282875cc
commit 327a69379a
2 changed files with 62 additions and 35 deletions

5
.prettierrc.js Normal file
View File

@ -0,0 +1,5 @@
"use strict";
module.exports = {
singleQuote: true,
};

View File

@ -1,4 +1,6 @@
require('dotenv').config()
#!/usr/bin/env node
require('dotenv').config();
const GiteaReviews = require('./lib/gitea-reviews');
const GithubReviews = require('./lib/github-reviews');
@ -6,8 +8,8 @@ const ethers = require('ethers');
const Kredits = require('kredits-contracts');
const util = require('util');
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
const providerUrl = process.env.KREDITS_PROVIDER_URL;
const daoAddress = process.env.KREDITS_DAO_ADDRESS;
@ -15,13 +17,13 @@ const daoAddress = process.env.KREDITS_DAO_ADDRESS;
const ipfsConfig = {
host: process.env.IPFS_API_HOST || 'localhost',
port: process.env.IPFS_API_PORT || '5001',
protocol: process.env.IPFS_API_PROTOCOL || 'http'
protocol: process.env.IPFS_API_PROTOCOL || 'http',
};
const kreditsAmounts = {
'kredits-1': 100,
'kredits-2': 300,
'kredits-3': 1000
'kredits-3': 1000,
};
const repos = require('./repos.json');
@ -29,23 +31,28 @@ const repos = require('./repos.json');
const argv = yargs(hideBin(process.argv))
.option('start', {
alias: 's',
description: 'Include reviews for PRs merged after this date'
description: 'Include reviews for PRs merged after this date',
})
.option('end', {
alias: 'e',
description: 'Include reviews for PRs merged before this date'
description: 'Include reviews for PRs merged before this date',
})
.help()
.version()
.demandOption('start', 'Please provide a start date')
.default('end', function now() {
return (new Date()).toISOString().split('.')[0]+"Z";
return new Date().toISOString().split('.')[0] + 'Z';
})
.example([
['$0 --start 2020-11-01 --end 2020-11-30T23:59:59Z', 'Create contributions for reviews of pull requests merged in November 2020'],
['$0 --start 2021-01-01', 'Create contributions for reviews of pull requests merged from Januar 2021 until now'],
])
.argv
[
'$0 --start 2020-11-01 --end 2020-11-30T23:59:59Z',
'Create contributions for reviews of pull requests merged in November 2020',
],
[
'$0 --start 2021-01-01',
'Create contributions for reviews of pull requests merged from Januar 2021 until now',
],
]).argv;
const startTimestamp = Date.parse(argv.start);
const endTimestamp = Date.parse(argv.end);
@ -64,14 +71,20 @@ const startDate = new Date(startTimestamp);
const endDate = new Date(endTimestamp);
async function getAllReviews(repos, startDate, endDate) {
const githubReviews = new GithubReviews(process.env.GITHUB_TOKEN, kreditsAmounts);
const giteaReviews = new GiteaReviews(process.env.GITEA_TOKEN, kreditsAmounts);
const githubReviews = new GithubReviews(
process.env.GITHUB_TOKEN,
kreditsAmounts
);
const giteaReviews = new GiteaReviews(
process.env.GITEA_TOKEN,
kreditsAmounts
);
return Promise.all([
githubReviews.getReviewContributions(repos.github, startDate, endDate),
giteaReviews.getReviewContributions(repos.gitea, startDate, endDate)
]).then(reviews => {
return { github: reviews[0], gitea: reviews[1] }
giteaReviews.getReviewContributions(repos.gitea, startDate, endDate),
]).then((reviews) => {
return { github: reviews[0], gitea: reviews[1] };
});
}
@ -110,21 +123,25 @@ async function initializeKredits () {
async function generateContributionData(reviews, Contributor) {
const contributors = await Contributor.all();
const contributionData = {};
const now = (new Date()).toISOString().split('.')[0]+"Z";
const now = new Date().toISOString().split('.')[0] + 'Z';
[date, time] = now.split('T');
function addContributionDataForPlatform(platform) {
for (const [username, platformReviews] of Object.entries(reviews[platform])) {
const contributor = contributors.find(c => {
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 ${platform} user "${username}"`);
console.log(
`Could not find contributor for ${platform} user "${username}"`
);
continue;
}
const urls = platformReviews.map(review => review.pr.html_url);
const urls = platformReviews.map((review) => review.pr.html_url);
const kreditsAmount = platformReviews.reduce((amount, review) => {
return review.kredits + amount;
}, 0);
@ -142,9 +159,9 @@ async function generateContributionData(reviews, Contributor) {
kind: 'dev',
description: 'PR reviews',
details: {
'pullRequests': urls
}
}
pullRequests: urls,
},
};
}
}
}
@ -155,13 +172,18 @@ async function generateContributionData(reviews, Contributor) {
return contributionData;
}
Promise.all([initializeKredits(), getAllReviews(repos, startDate, endDate)]).then((values) => {
Promise.all([
initializeKredits(),
getAllReviews(repos, startDate, endDate),
]).then((values) => {
const kredits = values[0];
const reviews = values[1];
generateContributionData(reviews, kredits.Contributor).then(contributionData => {
generateContributionData(reviews, kredits.Contributor).then(
(contributionData) => {
console.log('contributions:');
console.log(util.inspect(contributionData, { depth: 3, colors: true }));
}
);
});
});