<commit_before>var crypto = require('crypto');
var key = 'refViOctitJepyicejNikweomceyWoid';

module.exports = {
  process: function(req, callback) {
    if (!req.headers['x-hub-signature'])
      throw new Error('No X-Hub-Signature found on request');

    if (!req.headers['x-github-event'])
      throw new Error('No X-Github-Event found on request');

    if (!req.headers['x-github-delivery'])
      throw new Error('No X-Github-Delivery found on request');

    var received_sig = req.headers['x-hub-signature'];
    req.hasher = crypto.createHmac('sha1', key);
    req.setEncoding('utf8');
    var data = '';
    req.on('data', function (chunk) {
      data += chunk;
      req.hasher.update(chunk);
    });
    req.on('end', function() {
      req.body = JSON.parse(data);
      var hash = 'sha1=' + req.hasher.digest('hex');
      if (hash != received_sig) {
        callback(null, 403);
      } else {
        // this is a valid webhook from GitHub

        // contact GitHub
        //
        // Get all issues with the same label as the one
        // from the webhook and return the whole object
        //
        // Also get associated milestones and parse them
        callback(req.body, null);
      }
    });
  }
};<commit_msg>Module now exports a factory that receives a config object.<commit_after>var crypto = require('crypto');

module.exports = function (config) {
  if (!config.github) {
    throw new Error('No configuration found');
  }
  config = config.github;

  return {
    process: function(req, callback) {
      if (!req.headers['x-hub-signature']) {
        throw new Error('No X-Hub-Signature found on request');
      }

      if (!req.headers['x-github-event']) {
        throw new Error('No X-Github-Event found on request');
      }

      if (!req.headers['x-github-delivery']) {
        throw new Error('No X-Github-Delivery found on request');
      }

      var received_sig = req.headers['x-hub-signature'];
      req.hasher = crypto.createHmac('sha1', config.key);
      req.setEncoding('utf8');
      var data = '';
      req.on('data', function (chunk) {
        data += chunk;
        req.hasher.update(chunk);
      });
      req.on('end', function() {
        req.body = JSON.parse(data);
        var hash = 'sha1=' + req.hasher.digest('hex');
        if (hash != received_sig) {
          callback(null, 403);
        } else {
          // this is a valid webhook from GitHub

          // contact GitHub
          //
          // Get all issues with the same label as the one
          // from the webhook and return the whole object
          //
          // Also get associated milestones and parse them
          callback(req.body, null);
        }
      });
    }
  };
};
{'fraction_non_alphanumeric': 0.14181018688164163, 'fraction_numerical': 0.004397215097105167, 'mean_word_length': 2.19672131147541, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5020019', 'n_tokens_mistral': 823, 'n_tokens_neox': 798, 'n_words': 222}