<commit_before>var config = require('../configurations');
var request = require('request');

function Redmine(karma) {
    this.karma = karma;
    this.lastUpdated = new Date();
}

Redmine.prototype.setup = function(irc) {
    var that = this;
    this.irc = irc;

    setInterval(function() {
        that.update().then(function(issues) {
            that.handleIssues(issues);
        });
    }, config.redmine.intervalMs);
};

Redmine.prototype.handleIssues = function (issues) {
    var that = this;

    issues.forEach(function(issue) {
        if(issue.assigned_to && issue.assigned_to.name) {
            var msg = [
                issue.assigned_to.name, 'completed ticket', '"' + issue.subject + '"',
                '<' + config.redmine.url + '/issues/' + issue.id + '>'
            ];

            that.karma.incrementKarma(config.assigned_to.name);
            that.irc.say(msg.join(' '));
        }
    });
};

Redmine.prototype.update = function() {

    var options = {
        url: config.redmine.url + '/projects/' + config.redmine.project + '/issues.json',
        auth: {
            user: config.redmine.username,
            password: <PASSWORD>
        },
        qs: {
            closed_on: '>=' + this.lastUpdated.toISOString().slice(0, 10),
            status_id: 4,
            sort: 'closed_on:desc'
        }
    };

    return new Promise(function(resolve, reject) {

        request(options, function (error, response, body) {

            if(error) {
                return reject(error);
            }

            try {
                var result = JSON.parse(body);

                if(!result.issues) {
                    return reject('Can\'t find attribute issues');
                }

                that.lastUpdated = new Date();
                return resolve(result.issues);
            } catch (e) {
                return reject('Invalid JSON');<commit_msg>Fix #5: Use correct timestamp for redmine query<commit_after>var config = require('../configurations');
var request = require('request');

function Redmine(karma) {
    this.karma = karma;
    this.lastUpdated = new Date();
}

Redmine.prototype.setup = function(irc) {
    var that = this;
    this.irc = irc;

    setInterval(function() {
        that.update().then(function(issues) {
            that.handleIssues(issues);
        });
    }, config.redmine.intervalMs);
};

Redmine.prototype.handleIssues = function (issues) {
    var that = this;

    issues.forEach(function(issue) {
        if(issue.assigned_to && issue.assigned_to.name) {
            var msg = [
                issue.assigned_to.name, 'completed ticket', '"' + issue.subject + '"',
                '<' + config.redmine.url + '/issues/' + issue.id + '>'
            ];

            that.karma.incrementKarma(issue.assigned_to.name);
            that.irc.say(msg.join(' '));
        }
    });
};

Redmine.prototype.update = function() {

    var that = this;
    var options = {
        url: config.redmine.url + '/projects/' + config.redmine.project + '/issues.json',
        auth: {
            user: config.redmine.username,
            password: <PASSWORD>
        },
        qs: {
            closed_on: '>=' + this.lastUpdated.toISOString().slice(0, 19),
            status_id: 4,
            sort: 'closed_on:desc'
        }
    };

    return new Promise(function(resolve, reject) {

        request(options, function (error, response, body) {

            if(error) {
                return reject(error);
            }

            try {
                var result = JSON.parse(body);

                if(!result.issues) {
                    return reject('Can\'t find attribute issues');
                }

                that.lastUpdated = new Date();
                return resolve(result.issues);
            } catch (e) {
                return reject('Invalid JSON');
{'fraction_non_alphanumeric': 0.13930605903676851, 'fraction_numerical': 0.002330398757120663, 'mean_word_length': 1.7751436781609196, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5249286', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1085, 'n_words': 205}