<commit_before>/**
 * Created by Andrew on 11/6/2014.
 */

var crypto = require('crypto');
var execFile = require('child_process').execFile;


/**
 * POST /webhook
 * Update the repo
 */

exports.webhook = function(req, res) {

    // JSON payload from Github
    var jsonPayload= req.body;

    // Read the signature header from Github
    reqGithubHash = req.header('X-Hub-Signature');
    console.log(reqGithubHash);

    // Define secret (from Github) and stringify the payload to use as data for the SHA1 HMAC Hex Digest
    var secret = 'Every. Single. Night.';
    var data = JSON.stringify(jsonPayload);

    // Compute the hash using the secret as the key, and the payload as the data to hash
    var computedHash = crypto.createHmac('sha1', secret).update(data).digest('hex');
    computedHash = "sha1=" + computedHash;
    console.log(computedHash);

    // Compare the two hashes to see if the secrets matched
    if (reqGithubHash == computedHash) {

        // If the secrets matched and the push was to the master branch, update the local repo and send a '200 OK' response
        if (jsonPayload.ref == "refs/heads/master") {
            execFile('/var/www/gitpull.sh', [], {}, function(error, stdout, stderr){
                console.log("shell script executed");
                console.log(stdout);
                console.log(stderr);
                res.status(200).send("Local repository updated!");
            });
        }
        else {
            res.status(200).send("Local repository not updated! The master branch was not pushed.");
        }
    }
    // If the secrets didn't match, then send a '403 Forbidden' response
    else {
        res.status(403).send("Secrets do not match.");
    }
};


/**
 * GET /webhook
 * Tell people that this is the webhook stuff<commit_msg>changed up webhook<commit_after>/**
 * Created by Andrew on 11/6/2014.
 */

var crypto = require('crypto');
var execFile = require('child_process').execFile;
var exec = require('child_process').exec;


/**
 * POST /webhook
 * Update the repo
 */

exports.webhook = function(req, res) {

    // JSON payload from Github
    var jsonPayload= req.body;

    // Read the signature header from Github
    reqGithubHash = req.header('X-Hub-Signature');
    console.log(reqGithubHash);

    // Define secret (from Github) and stringify the payload to use as data for the SHA1 HMAC Hex Digest
    var secret = 'Every. Single. Night.';
    var data = JSON.stringify(jsonPayload);

    // Compute the hash using the secret as the key, and the payload as the data to hash
    var computedHash = crypto.createHmac('sha1', secret).update(data).digest('hex');
    computedHash = "sha1=" + computedHash;
    console.log(computedHash);

    // Compare the two hashes to see if the secrets matched
    if (reqGithubHash == computedHash) {

        // If the secrets matched and the push was to the master branch, update the local repo and send a '200 OK' response
        if (jsonPayload.ref == "refs/heads/master") {
            exec('cd /var/www && git pull', function(error, stdout, stderr){
                console.log("shell script executed");
                console.log(stdout);
                res.status(200).send("Local repository updated!");
            });
        }
        else {
            res.status(200).send("Local repository not updated! The master branch was not pushed.");
        }
    }
    // If the secrets didn't match, then send a '403 Forbidden' response
    else {
        res.status(403).send("Secrets do not match.");
    }
};


/**
 * GET /webhook
 * Tell people that this is the webhook stuff
{'fraction_non_alphanumeric': 0.11698008849557522, 'fraction_numerical': 0.013827433628318585, 'mean_word_length': 2.5882936507936507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2721048', 'n_tokens_mistral': 1060, 'n_tokens_neox': 996, 'n_words': 354}