Improve logging
This commit is contained in:
		
							parent
							
								
									aab5b58bab
								
							
						
					
					
						commit
						48a42d4f2c
					
				
							
								
								
									
										4
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								index.js
									
									
									
									
									
								
							@ -123,7 +123,7 @@ module.exports = async function(robot) {
 | 
			
		||||
      // current block is the last mined one, thus we check from the next
 | 
			
		||||
      // mined one onwards to prevent getting previous events
 | 
			
		||||
      let nextBlock = blockNumber + 1;
 | 
			
		||||
      robot.logger.debug(`[kredits] watching events from block ${nextBlock} onward`);
 | 
			
		||||
      robot.logger.debug(`[hubot-kredits] Watching events from block ${nextBlock} onward`);
 | 
			
		||||
      ethProvider.resetEventsBlock(nextBlock);
 | 
			
		||||
 | 
			
		||||
      Operator.on('ProposalCreated', handleProposalCreated);
 | 
			
		||||
@ -133,7 +133,7 @@ module.exports = async function(robot) {
 | 
			
		||||
  function handleProposalCreated(proposalId, creatorAccount, contributorId, amount) {
 | 
			
		||||
    Contributor.getById(contributorId).then((contributor) => {
 | 
			
		||||
      Operator.getById(proposalId).then((proposal) => {
 | 
			
		||||
        console.debug('Proposal created:', proposal);
 | 
			
		||||
        robot.logger.debug(`[hubot-kredits] Proposal created (${proposal.description})`);
 | 
			
		||||
        // messageRoom(`Let's give ${contributor.name} some kredits for ${proposal.url} (${proposal.description}): https://kredits.kosmos.org`);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
@ -3,7 +3,8 @@ const fetch = require('node-fetch');
 | 
			
		||||
 | 
			
		||||
module.exports = async function(robot, kredits) {
 | 
			
		||||
 | 
			
		||||
  robot.logger.debug('[hubot-kredits] Loading GitHub integration...')
 | 
			
		||||
  robot.logger.debug('[hubot-kredits] Loading GitHub integration...');
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  const Contributor = kredits.Contributor;
 | 
			
		||||
  const Operator = kredits.Operator;
 | 
			
		||||
@ -22,8 +23,9 @@ module.exports = async function(robot, kredits) {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  function createProposal(githubUser, amount, description, url, details) {
 | 
			
		||||
    return getContributorByGithubUser(githubUser).then((contributor) => {
 | 
			
		||||
      robot.logger.debug(`[kredits] Creating proposal to issue ${amount}₭S to ${githubUser} for ${url}...`);
 | 
			
		||||
    return getContributorByGithubUser(githubUser).then(contributor => {
 | 
			
		||||
      robot.logger.debug(`[hubot-kredits] Creating proposal to issue ${amount}₭S to ${githubUser} for ${url}...`);
 | 
			
		||||
 | 
			
		||||
      let contributionAttr = {
 | 
			
		||||
        contributorId: contributor.id,
 | 
			
		||||
        amount: amount,
 | 
			
		||||
@ -33,13 +35,12 @@ module.exports = async function(robot, kredits) {
 | 
			
		||||
        details,
 | 
			
		||||
        kind: 'dev'
 | 
			
		||||
      };
 | 
			
		||||
      return Operator.addProposal(contributionAttr).then((result) => {
 | 
			
		||||
          robot.logger.debug('[kredits] proposal created:', util.inspect(result));
 | 
			
		||||
        });
 | 
			
		||||
      }).catch((error) => {
 | 
			
		||||
 | 
			
		||||
      return Operator.addProposal(contributionAttr).catch(error => {
 | 
			
		||||
        robot.logger.info(`[hubot-kredits] Error:`, error);
 | 
			
		||||
        messageRoom(`I wanted to propose giving kredits to ${githubUser} for ${url}, but I can't find their contact data. Please add them as a contributor: https://kredits.kosmos.org`);
 | 
			
		||||
        messageRoom(`I wanted to propose giving kredits to ${githubUser} for ${url}, but I cannot find their contact data. Please add them as a contributor: https://kredits.kosmos.org`);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  function amountFromIssueLabels(issue) {
 | 
			
		||||
 | 
			
		||||
@ -54,7 +54,7 @@ module.exports = async function(robot, kredits) {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  function analyzeUserChanges (user, changes) {
 | 
			
		||||
    robot.logger.info(`Analyzing ${changes.length} edits from ${user} ...`);
 | 
			
		||||
    robot.logger.debug(`Analyzing ${changes.length} edits from ${user} ...`);
 | 
			
		||||
    const results = {};
 | 
			
		||||
 | 
			
		||||
    results.pagesCreated = changes.filter(c => c.type === 'new');
 | 
			
		||||
@ -63,9 +63,9 @@ module.exports = async function(robot, kredits) {
 | 
			
		||||
      .map(c => { return (c.oldlen < c.newlen) ? (c.newlen - c.oldlen) : 0; })
 | 
			
		||||
      .reduce((a, b) => a + b);
 | 
			
		||||
 | 
			
		||||
    robot.logger.info(`Created ${results.pagesCreated.length} pages`);
 | 
			
		||||
    robot.logger.info(`Edited ${results.pagesChanged.length} pages`);
 | 
			
		||||
    robot.logger.info(`Added ${results.linesAdded} lines of text\n`);
 | 
			
		||||
    robot.logger.debug(`Created ${results.pagesCreated.length} pages`);
 | 
			
		||||
    robot.logger.debug(`Edited ${results.pagesChanged.length} pages`);
 | 
			
		||||
    robot.logger.debug(`Added ${results.linesAdded} lines of text\n`);
 | 
			
		||||
 | 
			
		||||
    return results;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user