Add prettier config
This commit is contained in:
parent
a5282875cc
commit
327a69379a
5
.prettierrc.js
Normal file
5
.prettierrc.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
singleQuote: true,
|
||||||
|
};
|
92
index.js
92
index.js
@ -1,4 +1,6 @@
|
|||||||
require('dotenv').config()
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
require('dotenv').config();
|
||||||
const GiteaReviews = require('./lib/gitea-reviews');
|
const GiteaReviews = require('./lib/gitea-reviews');
|
||||||
const GithubReviews = require('./lib/github-reviews');
|
const GithubReviews = require('./lib/github-reviews');
|
||||||
|
|
||||||
@ -6,22 +8,22 @@ const ethers = require('ethers');
|
|||||||
const Kredits = require('kredits-contracts');
|
const Kredits = require('kredits-contracts');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
|
||||||
const yargs = require('yargs/yargs')
|
const yargs = require('yargs/yargs');
|
||||||
const { hideBin } = require('yargs/helpers')
|
const { hideBin } = require('yargs/helpers');
|
||||||
|
|
||||||
const providerUrl = process.env.KREDITS_PROVIDER_URL;
|
const providerUrl = process.env.KREDITS_PROVIDER_URL;
|
||||||
const daoAddress = process.env.KREDITS_DAO_ADDRESS;
|
const daoAddress = process.env.KREDITS_DAO_ADDRESS;
|
||||||
|
|
||||||
const ipfsConfig = {
|
const ipfsConfig = {
|
||||||
host: process.env.IPFS_API_HOST || 'localhost',
|
host: process.env.IPFS_API_HOST || 'localhost',
|
||||||
port: process.env.IPFS_API_PORT || '5001',
|
port: process.env.IPFS_API_PORT || '5001',
|
||||||
protocol: process.env.IPFS_API_PROTOCOL || 'http'
|
protocol: process.env.IPFS_API_PROTOCOL || 'http',
|
||||||
};
|
};
|
||||||
|
|
||||||
const kreditsAmounts = {
|
const kreditsAmounts = {
|
||||||
'kredits-1': 100,
|
'kredits-1': 100,
|
||||||
'kredits-2': 300,
|
'kredits-2': 300,
|
||||||
'kredits-3': 1000
|
'kredits-3': 1000,
|
||||||
};
|
};
|
||||||
|
|
||||||
const repos = require('./repos.json');
|
const repos = require('./repos.json');
|
||||||
@ -29,23 +31,28 @@ const repos = require('./repos.json');
|
|||||||
const argv = yargs(hideBin(process.argv))
|
const argv = yargs(hideBin(process.argv))
|
||||||
.option('start', {
|
.option('start', {
|
||||||
alias: 's',
|
alias: 's',
|
||||||
description: 'Include reviews for PRs merged after this date'
|
description: 'Include reviews for PRs merged after this date',
|
||||||
})
|
})
|
||||||
.option('end', {
|
.option('end', {
|
||||||
alias: 'e',
|
alias: 'e',
|
||||||
description: 'Include reviews for PRs merged before this date'
|
description: 'Include reviews for PRs merged before this date',
|
||||||
})
|
})
|
||||||
.help()
|
.help()
|
||||||
.version()
|
.version()
|
||||||
.demandOption('start', 'Please provide a start date')
|
.demandOption('start', 'Please provide a start date')
|
||||||
.default('end', function now () {
|
.default('end', function now() {
|
||||||
return (new Date()).toISOString().split('.')[0]+"Z";
|
return new Date().toISOString().split('.')[0] + 'Z';
|
||||||
})
|
})
|
||||||
.example([
|
.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'],
|
'$0 --start 2020-11-01 --end 2020-11-30T23:59:59Z',
|
||||||
])
|
'Create contributions for reviews of pull requests merged in November 2020',
|
||||||
.argv
|
],
|
||||||
|
[
|
||||||
|
'$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 startTimestamp = Date.parse(argv.start);
|
||||||
const endTimestamp = Date.parse(argv.end);
|
const endTimestamp = Date.parse(argv.end);
|
||||||
@ -64,18 +71,24 @@ const startDate = new Date(startTimestamp);
|
|||||||
const endDate = new Date(endTimestamp);
|
const endDate = new Date(endTimestamp);
|
||||||
|
|
||||||
async function getAllReviews(repos, startDate, endDate) {
|
async function getAllReviews(repos, startDate, endDate) {
|
||||||
const githubReviews = new GithubReviews(process.env.GITHUB_TOKEN, kreditsAmounts);
|
const githubReviews = new GithubReviews(
|
||||||
const giteaReviews = new GiteaReviews(process.env.GITEA_TOKEN, kreditsAmounts);
|
process.env.GITHUB_TOKEN,
|
||||||
|
kreditsAmounts
|
||||||
|
);
|
||||||
|
const giteaReviews = new GiteaReviews(
|
||||||
|
process.env.GITEA_TOKEN,
|
||||||
|
kreditsAmounts
|
||||||
|
);
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
githubReviews.getReviewContributions(repos.github, startDate, endDate),
|
githubReviews.getReviewContributions(repos.github, startDate, endDate),
|
||||||
giteaReviews.getReviewContributions(repos.gitea, startDate, endDate)
|
giteaReviews.getReviewContributions(repos.gitea, startDate, endDate),
|
||||||
]).then(reviews => {
|
]).then((reviews) => {
|
||||||
return { github: reviews[0], gitea: reviews[1] }
|
return { github: reviews[0], gitea: reviews[1] };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initializeKredits () {
|
async function initializeKredits() {
|
||||||
//
|
//
|
||||||
// Ethereum provider/node setup
|
// Ethereum provider/node setup
|
||||||
//
|
//
|
||||||
@ -99,7 +112,7 @@ async function initializeKredits () {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
kredits = await new Kredits(ethProvider, null, opts).init();
|
kredits = await new Kredits(ethProvider, null, opts).init();
|
||||||
} catch(error) {
|
} catch (error) {
|
||||||
console.log('Could not set up kredits:', error);
|
console.log('Could not set up kredits:', error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@ -110,21 +123,25 @@ 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";
|
const now = new Date().toISOString().split('.')[0] + 'Z';
|
||||||
[date, time] = now.split('T');
|
[date, time] = now.split('T');
|
||||||
|
|
||||||
function addContributionDataForPlatform(platform) {
|
function addContributionDataForPlatform(platform) {
|
||||||
for (const [username, platformReviews] of Object.entries(reviews[platform])) {
|
for (const [username, platformReviews] of Object.entries(
|
||||||
const contributor = contributors.find(c => {
|
reviews[platform]
|
||||||
|
)) {
|
||||||
|
const contributor = contributors.find((c) => {
|
||||||
return c[`${platform}_username`] === username;
|
return c[`${platform}_username`] === username;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!contributor) {
|
if (!contributor) {
|
||||||
console.log(`Could not find contributor for ${platform} user "${username}"`);
|
console.log(
|
||||||
|
`Could not find contributor for ${platform} user "${username}"`
|
||||||
|
);
|
||||||
continue;
|
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) => {
|
const kreditsAmount = platformReviews.reduce((amount, review) => {
|
||||||
return review.kredits + amount;
|
return review.kredits + amount;
|
||||||
}, 0);
|
}, 0);
|
||||||
@ -142,9 +159,9 @@ async function generateContributionData(reviews, Contributor) {
|
|||||||
kind: 'dev',
|
kind: 'dev',
|
||||||
description: 'PR reviews',
|
description: 'PR reviews',
|
||||||
details: {
|
details: {
|
||||||
'pullRequests': urls
|
pullRequests: urls,
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,13 +172,18 @@ async function generateContributionData(reviews, Contributor) {
|
|||||||
return contributionData;
|
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 kredits = values[0];
|
||||||
const reviews = values[1];
|
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 }));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
Reference in New Issue
Block a user