12 Commits

Author SHA1 Message Date
Râu Cao
dd89f96bee 4.1.0 2023-08-14 17:31:10 +02:00
Râu Cao
90bb475f0d Merge pull request #70 from 67P/chore/update_dependencies
Update dependencies (incl. new contracts)
2023-08-14 17:23:46 +02:00
Râu Cao
dabd997004 Update dependencies (incl. new contracts)
Needs some code updates for grant v5
2023-08-14 17:21:10 +02:00
Râu Cao
c196ded52c Update lockfile 2023-01-19 14:59:34 +08:00
Râu Cao
f74ccdc7ff Remove obsolete code 2023-01-19 14:59:01 +08:00
Râu Cao
86dd3b6979 4.0.2 2022-11-02 19:10:42 +01:00
Râu Cao
948e536327 Update npm badge 2022-11-02 19:10:29 +01:00
Greg Karékinian
b6b91bef5b Merge pull request #68 from 67P/chore/kredits_upgrade
Update and adapt for new kredits contracts release
2022-11-02 19:09:09 +01:00
Greg Karékinian
7db7a83a34 Merge pull request #67 from 67P/bugfix/fix_wallet_loading
Fix wallet loading in review-kredits script
2021-03-30 14:06:30 +02:00
2e840bcb2b Fix wallet loading in review-kredits script
Requiring the wallet JSON file parses it, so we have to read it directly
from the filesystem instead.
2021-03-30 13:51:34 +02:00
09637121be Merge pull request #66 from 67P/feature/49-create_review_contributions
Create contributions for PR reviews
2021-03-29 10:43:22 +02:00
86f614ceee Create contributions for PR reviews
Refs #49
2021-01-29 12:33:38 +01:00
6 changed files with 1666 additions and 2104 deletions

View File

@@ -1,4 +1,4 @@
[![npm](https://img.shields.io/npm/v/hubot-kredits.svg)](https://www.npmjs.com/package/hubot-kredits)
[![npm](https://img.shields.io/npm/v/@kredits/hubot-kredits.svg)](https://www.npmjs.com/package/@kredits/hubot-kredits)
# Hubot Kredits

View File

@@ -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;

View File

@@ -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

File diff suppressed because it is too large Load Diff

View File

@@ -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",

View File

@@ -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
});
});