Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd89f96bee
|
||
|
|
90bb475f0d | ||
|
|
dabd997004
|
||
|
|
c196ded52c
|
||
|
|
f74ccdc7ff
|
||
|
|
86dd3b6979
|
||
|
|
948e536327
|
||
|
|
b6b91bef5b | ||
|
|
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
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const util = require('util');
|
||||
const fetch = require('node-fetch');
|
||||
const session = require('express-session');
|
||||
const grant = require('grant-express');
|
||||
const cors = require('cors');
|
||||
const grant = require('grant').express();
|
||||
const amountFromLabels = require('./utils/amount-from-labels');
|
||||
const kindFromLabels = require('./utils/kind-from-labels');
|
||||
|
||||
@@ -184,11 +184,10 @@ module.exports = async function(robot, kredits) {
|
||||
if (process.env.KREDITS_GITHUB_KEY && process.env.KREDITS_GITHUB_SECRET) {
|
||||
const grantConfig = {
|
||||
defaults: {
|
||||
protocol: (process.env.KREDITS_GRANT_PROTOCOL || "http"),
|
||||
host: (process.env.KREDITS_GRANT_HOST || 'localhost:8888'),
|
||||
origin: (process.env.KREDITS_GRANT_ORIGIN || 'http://localhost:8888'),
|
||||
prefix: '/kredits/signup/connect',
|
||||
transport: 'session',
|
||||
response: 'tokens',
|
||||
path: '/kredits/signup'
|
||||
},
|
||||
github: {
|
||||
key: process.env.KREDITS_GITHUB_KEY,
|
||||
@@ -203,7 +202,7 @@ module.exports = async function(robot, kredits) {
|
||||
saveUninitialized: false
|
||||
}));
|
||||
|
||||
robot.router.use('/kredits/signup', grant(grantConfig));
|
||||
robot.router.use(grant(grantConfig));
|
||||
|
||||
robot.router.get('/kredits/signup/github', async (req, res) => {
|
||||
const access_token = req.session.grant.response.access_token;
|
||||
|
||||
@@ -112,14 +112,10 @@ module.exports = async function(robot, kredits) {
|
||||
}
|
||||
|
||||
async function createContributions (changes) {
|
||||
let promises = [];
|
||||
|
||||
for (const user of Object.keys(changes)) {
|
||||
await createContributionForUserChanges(user, changes[user]);
|
||||
await sleep(60000);
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function pageTitlesFromChanges(changes) {
|
||||
|
||||
3685
package-lock.json
generated
3685
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kredits/hubot-kredits",
|
||||
"version": "4.0.1",
|
||||
"version": "4.1.0",
|
||||
"description": "Kosmos Kredits functionality for chat bots",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@@ -11,21 +11,21 @@
|
||||
"review-kredits": "scripts/review-kredits.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ethersproject/experimental": "5.0.0",
|
||||
"@kredits/contracts": "^7.0.0",
|
||||
"@ethersproject/experimental": "5.7.0",
|
||||
"@kredits/contracts": "^7.3.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^8.2.0",
|
||||
"eth-provider": "^0.2.2",
|
||||
"dotenv": "^16.3.1",
|
||||
"eth-provider": "^0.13.6",
|
||||
"ethers": "^5.0.5",
|
||||
"express": "^4.17.1",
|
||||
"express-session": "^1.16.2",
|
||||
"grant-express": "^4.6.1",
|
||||
"express": "^4.18.2",
|
||||
"express-session": "^1.17.3",
|
||||
"grant-express": "^5.4.8",
|
||||
"group-array": "^1.0.0",
|
||||
"kosmos-schemas": "^1.1.2",
|
||||
"kosmos-schemas": "^2.2.1",
|
||||
"node-cron": "^2.0.3",
|
||||
"node-fetch": "^2.3.0",
|
||||
"prompt": "^1.0.0",
|
||||
"yargs": "^16.2.0"
|
||||
"node-fetch": "^2.6.12",
|
||||
"prompt": "^1.3.0",
|
||||
"yargs": "^17.7.2"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -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