From 327a69379a39dc1901bd7b0573e427f8fcecb8d5 Mon Sep 17 00:00:00 2001 From: Garret Alfert Date: Sun, 26 Feb 2023 22:49:11 +0100 Subject: [PATCH] Add prettier config --- .prettierrc.js | 5 +++ index.js | 92 +++++++++++++++++++++++++++++++------------------- 2 files changed, 62 insertions(+), 35 deletions(-) create mode 100644 .prettierrc.js diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..f145902 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,5 @@ +"use strict"; + +module.exports = { + singleQuote: true, +}; diff --git a/index.js b/index.js index 66aa48a..fc66833 100644 --- a/index.js +++ b/index.js @@ -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,22 +8,22 @@ 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; +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"; + .default('end', function now() { + 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,18 +71,24 @@ 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] }; }); } -async function initializeKredits () { +async function initializeKredits() { // // Ethereum provider/node setup // @@ -99,7 +112,7 @@ async function initializeKredits () { try { kredits = await new Kredits(ethProvider, null, opts).init(); - } catch(error) { + } catch (error) { console.log('Could not set up kredits:', error); process.exit(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 => { - console.log('contributions:'); - console.log(util.inspect(contributionData, { depth: 3, colors: true })); - }); -}); + generateContributionData(reviews, kredits.Contributor).then( + (contributionData) => { + console.log('contributions:'); + console.log(util.inspect(contributionData, { depth: 3, colors: true })); + } + ); +});