<commit_before>'use strict';

var debug = require('debug')('gitevents-milestone');
var config = require('../common/config');

var createMilestone = function createMilestone(payload, event, repo, github) {
  return new Promise(function(resolve, reject) {
    debug('createdMilestone()');
    github.issues.createMilestone({
      user: config.github.org,
      repo: repo,
      title: event.name,
      due_on: event.startDate,
      description: event.id
    }, function(error, milestone) {
      debug('GitHub:createdMilestone - ' + repo);
      if (error) {
        return reject(new Error(error));
      }
      return resolve({
        'milestone': milestone,
        'repo': repo
      });
    });
  });
};

var getMilestones = function getMilestones(repo, eventId, github) {
  return new Promise(function(resolve, reject) {
    debug('getMilestone()');
    github.issues.getAllMilestones({
      user: config.github.org,
      repo: repo,
      state: 'open'
    }, function(error, milestones) {
      debug('GitHub:getAllMilestones');
      if (error) {
        return reject(new Error(error));
      }

      if (milestones.length > 0) {
        milestones.forEach(function(milestone) {
          if (milestone.description === eventId) {
            return resolve({
              'milestone': milestone,
              'repo': repo
            });
          }
        });
        return resolve({
          'milestone': false,
          'repo': repo
        });
      } else {
        resolve({
          'milestone': false,
          'repo': repo
        });
      }
    });
  });
};

var addMilestone = function addMilestone(issueNumber, repo, milestoneNumber, github) {
  return new Promise(function(resolve, reject) {
    console.log(issueNumber, repo, milestoneNumber);
    debug('addMilestone()');
    github.issues.edit({
      user: config.github.org,
      repo: repo,
      number: issueNumber,
      milestone: milestoneNumber
    }, function(error, issue) {
      debug('GitHub:issues.edit()');
      console.log(error, issue);
      if (error) {
        return reject(new Error(error));
      }
      return resolve({
        'issue': issue
      });
    });<commit_msg>no-console<commit_after>'use strict';

var debug = require('debug')('gitevents-milestone');
var config = require('../common/config');

var createMilestone = function createMilestone(payload, event, repo, github) {
  return new Promise(function(resolve, reject) {
    debug('createdMilestone()');
    github.issues.createMilestone({
      user: config.github.org,
      repo: repo,
      title: event.name,
      due_on: event.startDate,
      description: event.id
    }, function(error, milestone) {
      debug('GitHub:createdMilestone - ' + repo);
      if (error) {
        return reject(new Error(error));
      }
      return resolve({
        'milestone': milestone,
        'repo': repo
      });
    });
  });
};

var getMilestones = function getMilestones(repo, eventId, github) {
  return new Promise(function(resolve, reject) {
    debug('getMilestone()');
    github.issues.getAllMilestones({
      user: config.github.org,
      repo: repo,
      state: 'open'
    }, function(error, milestones) {
      debug('GitHub:getAllMilestones');
      if (error) {
        return reject(new Error(error));
      }

      if (milestones.length > 0) {
        milestones.forEach(function(milestone) {
          if (milestone.description === eventId) {
            return resolve({
              'milestone': milestone,
              'repo': repo
            });
          }
        });
        return resolve({
          'milestone': false,
          'repo': repo
        });
      } else {
        resolve({
          'milestone': false,
          'repo': repo
        });
      }
    });
  });
};

var addMilestone = function addMilestone(issueNumber, repo, milestoneNumber, github) {
  return new Promise(function(resolve, reject) {
    debug('addMilestone()');
    github.issues.edit({
      user: config.github.org,
      repo: repo,
      number: issueNumber,
      milestone: milestoneNumber
    }, function(error, issue) {
      debug('GitHub:issues.edit()');
      if (error) {
        return reject(new Error(error));
      }
      return resolve({
        'issue': issue
      });
    });
{'fraction_non_alphanumeric': 0.13969732246798602, 'fraction_numerical': 0.00046565774155995343, 'mean_word_length': 2.302075326671791, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7439165', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1216, 'n_words': 265}