<commit_before>var async = require('async'),
    fs = require('fs'),
    GitHubAPI = require('github'),
    _ = require('underscore');

var github = new GitHubAPI({
    version: "3.0.0",
    protocol: "https",
    timeout: 5000
});

// Only auth if auth details given
github.tryAuthenticate = function() {
    var authType = config.type;
    var authed = false;
    if (authType.length) {
        this.authenticate(config);
        authed = true;
    }
    return authed;
}

var config;

function WatchManager() {
    var storageNamespace = "github",
        storageFilename = "watchman.json";

    var repos = {},
        issues = {};

    function GithubRepo(dataObj) {
        for (var prop in dataObj) this[prop] = dataObj[prop];

        var recentlySeen = [];

        this.checkForUpdates = function(callback) {
            var self = this;
            var hasChanged = false;

            github.tryAuthenticate();
            github.events.getFromRepo({
                user: this.user,
                repo: this.repo
            }, function(err, res) {
                if (err) {
                    callback(err, false);
                } else {
                    var mostRecent = res[0];
                    
                    if (mostRecent.id != self.lastSeenEventId) {
                        hasChanged = true;
                        var ls = self.lastSeenEventId;
                        // An update has occured, get unseen messages
                        var itr = 0,
                            currEvent = { id: '' };
                        recentlySeen = [];
                        if (res.length) currEvent = res[0];
                        while (itr < res.length && currEvent.id != ls) {
                            recentlySeen.push(currEvent);
                            itr ++;
                            currEvent = res[itr];
                        }
                        self.lastSeenEventId = mostRecent.id;
                    }
                    callback(null, hasChanged);
                }
            });
        }

        this.getHTMLUrl = function() {
            return "https://github.com/" + this.user + "/" + this.repo;
        }

        this.generateUpdateMessage = function() {
            var self = this;
            var msg = [];
            var key = this.getKey();
            _.each(recentlySeen, function(githubEvent) {
                var payload = githubEvent.payload,
                    user = githubEvent.actor.login;
                switch (githubEvent.type) {
                    case "CommitCommentEvent":
                        var comment = payload.comment;
                        var commitId = '[' + comment.commit_id.substr(0, 7) + 
                                '...]',
                            link = comment.html_url;
                        msg.push(["Github --", user, "commented on commit",
                            commitId, "for repo", key + '.', link].join(' '));
                        break;
                    case "PushEvent":
                        var numCommits = payload.size,
                            ref = payload.ref;
                        msg.push(["Github --", pusher, "pushed", numCommits,
                            "commits to", key + '.', "ref:", ref + '.',
                            self.getHTMLUrl].join(' '));
                        break;
                    case "IssuesEvent":
                        var action = payload.action,
                            issueNum = payload.issue.number,
                            title = payload.issue.title,
                            link = payload.issue.html_url;
                        msg.push(["Github --", user, action, "issue",
                                "#" + issueNum, "for repo", key + ":",
                                title + '.', link].join(' '));
                        break;
                    case "IssueCommentEvent":
                        var issueNum = payload.issue.number,
                            title = payload.issue.title,
                            link = payload.comment.html_url;
                        msg.push(["Github --", user, "commented on issue",
                                "#" + issueNum, "for repo", key + ":",
                                title + '.', link].join(' '));
                        break;
                    case "PullRequestEvent":
                        var action = payload.action,<commit_msg>Fixed typo-related bug :)<commit_after>var async = require('async'),
    fs = require('fs'),
    GitHubAPI = require('github'),
    _ = require('underscore');

var github = new GitHubAPI({
    version: "3.0.0",
    protocol: "https",
    timeout: 5000
});

// Only auth if auth details given
github.tryAuthenticate = function() {
    var authType = config.type;
    var authed = false;
    if (authType.length) {
        this.authenticate(config);
        authed = true;
    }
    return authed;
}

var config;

function WatchManager() {
    var storageNamespace = "github",
        storageFilename = "watchman.json";

    var repos = {},
        issues = {};

    function GithubRepo(dataObj) {
        for (var prop in dataObj) this[prop] = dataObj[prop];

        var recentlySeen = [];

        this.checkForUpdates = function(callback) {
            var self = this;
            var hasChanged = false;

            github.tryAuthenticate();
            github.events.getFromRepo({
                user: this.user,
                repo: this.repo
            }, function(err, res) {
                if (err) {
                    callback(err, false);
                } else {
                    var mostRecent = res[0];
                    
                    if (mostRecent.id != self.lastSeenEventId) {
                        hasChanged = true;
                        var ls = self.lastSeenEventId;
                        // An update has occured, get unseen messages
                        var itr = 0,
                            currEvent = { id: '' };
                        recentlySeen = [];
                        if (res.length) currEvent = res[0];
                        while (itr < res.length && currEvent.id != ls) {
                            recentlySeen.push(currEvent);
                            itr ++;
                            currEvent = res[itr];
                        }
                        self.lastSeenEventId = mostRecent.id;
                    }
                    callback(null, hasChanged);
                }
            });
        }

        this.getHTMLUrl = function() {
            return "https://github.com/" + this.user + "/" + this.repo;
        }

        this.generateUpdateMessage = function() {
            var self = this;
            var msg = [];
            var key = this.getKey();
            _.each(recentlySeen, function(githubEvent) {
                var payload = githubEvent.payload,
                    user = githubEvent.actor.login;
                switch (githubEvent.type) {
                    case "CommitCommentEvent":
                        var comment = payload.comment;
                        var commitId = '[' + comment.commit_id.substr(0, 7) + 
                                '...]',
                            link = comment.html_url;
                        msg.push(["Github --", user, "commented on commit",
                            commitId, "for repo", key + '.', link].join(' '));
                        break;
                    case "PushEvent":
                        var numCommits = payload.size,
                            ref = payload.ref;
                        msg.push(["Github --", user, "pushed", numCommits,
                            "commits to", key + '.', "ref:", ref + '.',
                            self.getHTMLUrl].join(' '));
                        break;
                    case "IssuesEvent":
                        var action = payload.action,
                            issueNum = payload.issue.number,
                            title = payload.issue.title,
                            link = payload.issue.html_url;
                        msg.push(["Github --", user, action, "issue",
                                "#" + issueNum, "for repo", key + ":",
                                title + '.', link].join(' '));
                        break;
                    case "IssueCommentEvent":
                        var issueNum = payload.issue.number,
                            title = payload.issue.title,
                            link = payload.comment.html_url;
                        msg.push(["Github --", user, "commented on issue",
                                "#" + issueNum, "for repo", key + ":",
                                title + '.', link].join(' '));
                        break;
                    case "PullRequestEvent":
                        var action = payload.action,
{'fraction_non_alphanumeric': 0.11159712875729026, 'fraction_numerical': 0.0026917900403768506, 'mean_word_length': 1.0344512890714124, 'pattern_counts': {'":': 14, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3675426', 'n_tokens_mistral': 2234, 'n_tokens_neox': 2097, 'n_words': 476}