Use robot.logger instead of console logs
This commit is contained in:
parent
217219fc68
commit
98a3ee087b
25
index.js
25
index.js
@ -16,6 +16,9 @@ const WalletSubprovider = require('ethereumjs-wallet/provider-engine');
|
|||||||
const Web3Subprovider = require('web3-provider-engine/subproviders/web3.js');
|
const Web3Subprovider = require('web3-provider-engine/subproviders/web3.js');
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
let engine = new ProviderEngine();
|
let engine = new ProviderEngine();
|
||||||
|
|
||||||
let walletPath = process.env.KREDITS_WALLET_PATH || './wallet.json';
|
let walletPath = process.env.KREDITS_WALLET_PATH || './wallet.json';
|
||||||
@ -40,20 +43,18 @@ web3.eth.defaultAccount = hubotWalletAddress;
|
|||||||
let contracts = kreditsContracts(web3, config);
|
let contracts = kreditsContracts(web3, config);
|
||||||
let kredits = contracts['Kredits'];
|
let kredits = contracts['Kredits'];
|
||||||
|
|
||||||
console.log('[HUBOT-KREDITS] Wallet address: ' + hubotWalletAddress);
|
module.exports = function(robot) {
|
||||||
|
|
||||||
(function() {
|
robot.logger.info('[hubot-kredits] Wallet address: ' + hubotWalletAddress);
|
||||||
"use strict";
|
|
||||||
|
|
||||||
web3.eth.getBalance(hubotWalletAddress, function (err, balance) {
|
web3.eth.getBalance(hubotWalletAddress, function (err, balance) {
|
||||||
if (err) { console.log('[HUBOT-KREDITS] Error checking balance'); return; }
|
if (err) { robot.logger.error('[hubot-kredits] Error checking balance'); return; }
|
||||||
if (balance <= 0) {
|
if (balance <= 0) {
|
||||||
console.log('[HUBOT-KREDITS] Hubot is broke. Please send some ETH to ' + hubotWalletAddress);
|
robot.logger.info('[hubot-kredits] Hubot is broke. Please send some ETH to ' + hubotWalletAddress);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let getValueFromContract = function(contractMethod, ...args) {
|
let getValueFromContract = function(contractMethod, ...args) {
|
||||||
console.log('[kredits] read from contract', contractMethod, ...args);
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
kredits[contractMethod](...args, (err, data) => {
|
kredits[contractMethod](...args, (err, data) => {
|
||||||
if (err) { reject(err); }
|
if (err) { reject(err); }
|
||||||
@ -65,16 +66,16 @@ console.log('[HUBOT-KREDITS] Wallet address: ' + hubotWalletAddress);
|
|||||||
let getContributorData = function(i) {
|
let getContributorData = function(i) {
|
||||||
let promise = new Promise((resolve, reject) => {
|
let promise = new Promise((resolve, reject) => {
|
||||||
getValueFromContract('contributorAddresses', i).then(address => {
|
getValueFromContract('contributorAddresses', i).then(address => {
|
||||||
console.log('address', address);
|
robot.logger.debug('address', address);
|
||||||
getValueFromContract('contributors', address).then(person => {
|
getValueFromContract('contributors', address).then(person => {
|
||||||
console.log('person', person);
|
robot.logger.debug('person', person);
|
||||||
let contributor = {
|
let contributor = {
|
||||||
address: address,
|
address: address,
|
||||||
github_username: person[1],
|
github_username: person[1],
|
||||||
github_uid: person[0],
|
github_uid: person[0],
|
||||||
ipfsHash: person[2]
|
ipfsHash: person[2]
|
||||||
};
|
};
|
||||||
console.log('[kredits] contributor', contributor);
|
robot.logger.debug('[kredits] contributor', contributor);
|
||||||
resolve(contributor);
|
resolve(contributor);
|
||||||
});
|
});
|
||||||
}).catch(err => reject(err));
|
}).catch(err => reject(err));
|
||||||
@ -110,8 +111,6 @@ console.log('[HUBOT-KREDITS] Wallet address: ' + hubotWalletAddress);
|
|||||||
return promise;
|
return promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = function(robot) {
|
|
||||||
|
|
||||||
function messageRoom(message) {
|
function messageRoom(message) {
|
||||||
robot.messageRoom(process.env.KREDITS_ROOM, message);
|
robot.messageRoom(process.env.KREDITS_ROOM, message);
|
||||||
}
|
}
|
||||||
@ -142,7 +141,7 @@ console.log('[HUBOT-KREDITS] Wallet address: ' + hubotWalletAddress);
|
|||||||
function createProposal(recipient, amount, url/*, metaData*/) {
|
function createProposal(recipient, amount, url/*, metaData*/) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// TODO write metaData to IPFS
|
// TODO write metaData to IPFS
|
||||||
console.log(`Creating proposal to issue ${amount}₭S to ${recipient} for ${url}...`);
|
robot.logger.debug(`Creating proposal to issue ${amount}₭S to ${recipient} for ${url}...`);
|
||||||
|
|
||||||
getContributorByGithubUser(recipient).then(c => {
|
getContributorByGithubUser(recipient).then(c => {
|
||||||
kredits.addProposal(c.address, amount, url, '', (e/* , d */) => {
|
kredits.addProposal(c.address, amount, url, '', (e/* , d */) => {
|
||||||
@ -221,7 +220,7 @@ console.log('[HUBOT-KREDITS] Wallet address: ' + hubotWalletAddress);
|
|||||||
robot.router.post('/incoming/kredits/github/'+process.env.KREDITS_WEBHOOK_TOKEN, (req, res) => {
|
robot.router.post('/incoming/kredits/github/'+process.env.KREDITS_WEBHOOK_TOKEN, (req, res) => {
|
||||||
let evt = req.header('X-GitHub-Event');
|
let evt = req.header('X-GitHub-Event');
|
||||||
let data = req.body;
|
let data = req.body;
|
||||||
console.log(`Received GitHub hook. Event: ${evt}, action: ${data.action}`);
|
robot.logger.debug(`Received GitHub hook. Event: ${evt}, action: ${data.action}`);
|
||||||
|
|
||||||
if (evt === 'pull_request' && data.action === 'closed') {
|
if (evt === 'pull_request' && data.action === 'closed') {
|
||||||
handleGitHubPullRequestClosed(data).then(() => res.send(200));
|
handleGitHubPullRequestClosed(data).then(() => res.send(200));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user