Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86dd3b6979
|
||
|
|
948e536327
|
||
|
|
b6b91bef5b | ||
|
|
48fa2e937b
|
||
|
|
de5ee5e323
|
||
|
|
7fb5fb747d
|
||
|
|
7db7a83a34 | ||
|
2e840bcb2b
|
|||
| 09637121be | |||
| 86f614ceee |
@@ -1,4 +1,4 @@
|
||||
[](https://www.npmjs.com/package/hubot-kredits)
|
||||
[](https://www.npmjs.com/package/@kredits/hubot-kredits)
|
||||
|
||||
# Hubot Kredits
|
||||
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "hubot-kredits",
|
||||
"version": "4.0.0",
|
||||
"version": "4.0.2",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "hubot-kredits",
|
||||
"version": "4.0.0",
|
||||
"version": "4.0.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@ethersproject/experimental": "5.0.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hubot-kredits",
|
||||
"version": "4.0.0",
|
||||
"name": "@kredits/hubot-kredits",
|
||||
"version": "4.0.2",
|
||||
"description": "Kosmos Kredits functionality for chat bots",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@@ -12,7 +12,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@ethersproject/experimental": "5.0.0",
|
||||
"@kredits/contracts": "7.0.0",
|
||||
"@kredits/contracts": "^7.0.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^8.2.0",
|
||||
"eth-provider": "^0.2.2",
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('dotenv').config({ path: '../.env' });
|
||||
require('dotenv').config({ path: '.env' });
|
||||
const GiteaReviews = require('./lib/gitea-reviews');
|
||||
const GithubReviews = require('./lib/github-reviews');
|
||||
|
||||
const ethers = require('ethers');
|
||||
const NonceManager = require('@ethersproject/experimental').NonceManager;
|
||||
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 fs = require('fs');
|
||||
|
||||
const walletPath = process.env.KREDITS_WALLET_PATH || '../wallet.json';
|
||||
const walletJson = fs.readFileSync(walletPath);
|
||||
const providerUrl = process.env.KREDITS_PROVIDER_URL;
|
||||
const daoAddress = process.env.KREDITS_DAO_ADDRESS;
|
||||
|
||||
@@ -84,12 +88,23 @@ async function getAllReviews(repos, startDate, endDate) {
|
||||
githubReviews.getReviewContributions(repos.github, startDate, endDate),
|
||||
giteaReviews.getReviewContributions(repos.gitea, startDate, endDate)
|
||||
]).then(reviews => {
|
||||
// console.log(util.inspect(reviews[0], { depth: 3, colors: true }));
|
||||
return { github: reviews[0], gitea: reviews[1] }
|
||||
});
|
||||
}
|
||||
|
||||
async function initializeKredits () {
|
||||
//
|
||||
// Ethereum wallet setup
|
||||
//
|
||||
|
||||
let wallet;
|
||||
try {
|
||||
wallet = await ethers.Wallet.fromEncryptedJson(walletJson, process.env.KREDITS_WALLET_PASSWORD);
|
||||
} catch(error) {
|
||||
console.log('Could not load wallet:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
//
|
||||
// Ethereum provider/node setup
|
||||
//
|
||||
@@ -100,6 +115,7 @@ async function initializeKredits () {
|
||||
} else {
|
||||
ethProvider = new ethers.getDefaultProvider('rinkeby');
|
||||
}
|
||||
const signer = new NonceManager(wallet.connect(ethProvider));
|
||||
|
||||
//
|
||||
// Kredits contracts setup
|
||||
@@ -112,7 +128,7 @@ async function initializeKredits () {
|
||||
let kredits;
|
||||
|
||||
try {
|
||||
kredits = await new Kredits(ethProvider, null, opts).init();
|
||||
kredits = await new Kredits(signer.provider, signer, opts).init();
|
||||
} catch(error) {
|
||||
console.log('Could not set up kredits:', error);
|
||||
process.exit(1);
|
||||
@@ -121,6 +137,17 @@ async function initializeKredits () {
|
||||
return kredits;
|
||||
}
|
||||
|
||||
function createContribution(contributorName, contributionAttributes, Contribution) {
|
||||
console.log(`Creating contribution token for ${contributionAttributes.amount}₭S to ${contributorName} for ${contributionAttributes.description}...`);
|
||||
|
||||
return Contribution.add(contributionAttributes).catch(error => {
|
||||
console.log(`I tried to add a contribution for ${contributorName}, but I encountered an error when submitting the tx:`);
|
||||
console.log(`Error:`, error);
|
||||
console.log('Contribution attributes:');
|
||||
console.log(util.inspect(contributionAttributes, { depth: 2, colors: true }));
|
||||
});
|
||||
}
|
||||
|
||||
async function generateContributionData(reviews, Contributor, startDate, endDate) {
|
||||
const dateFormatOptions = { year: 'numeric', month: 'long', day: 'numeric' };
|
||||
const contributors = await Contributor.all();
|
||||
@@ -179,11 +206,14 @@ Promise.all([initializeKredits(), getAllReviews(repos, startDate, endDate)]).the
|
||||
|
||||
generateContributionData(reviews, kredits.Contributor, startDate, endDate).then(contributionData => {
|
||||
if (argv.dry) {
|
||||
console.log('contributions:');
|
||||
console.log('Contributions:');
|
||||
console.log(util.inspect(contributionData, { depth: 3, colors: true }));
|
||||
} else {
|
||||
// create contributions
|
||||
for (const [username, contributionAttributes] of Object.entries(contributionData)) {
|
||||
createContribution(username, contributionAttributes, kredits.Contribution);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO create contributions
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user