<commit_before>'use strict';

const express = require('express');
const bodyParser = require('body-parser');
const crypto = require('crypto');

module.exports = function(eventEmitter, secret) {
  var app = express();

  function signBlob(key, blob) {
    return 'sha1=' + crypto.createHmac('sha1', key).update(blob).digest('hex');
  }

  app.use(bodyParser.urlencoded({
    extended: true,
    verify: function(req, res, buffer) {
      if (!req.get('x-hub-signature'))
        throw new Error('No X-Hub-Signature found on request');

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

      var signature = req.get('x-hub-signature');
      var computedSignature = signBlob(secret, buffer);

      console.log('verified', signature, computedSignature);

      if (signature !== computedSignature) {
        console.warn('Recieved an invalid HMAC: calculated:' +
          computedSignature + ' != recieved:' + signature);
        throw new Error('Invalid Signature');
      }
    }
  }));

  app.get('/', (req, res) => {
    res.status(200).send('pong!');
  });

  app.post('/ghwebook', (req, res) => {
    const event = req.get('x-github-event');
    eventEmitter.emit(event, req.body.payload);
    res.status(200).send('ok');<commit_msg>Parses the payload to json<commit_after>'use strict';

const express = require('express');
const bodyParser = require('body-parser');
const crypto = require('crypto');

module.exports = function(eventEmitter, secret) {
  var app = express();

  function signBlob(key, blob) {
    return 'sha1=' + crypto.createHmac('sha1', key).update(blob).digest('hex');
  }

  app.use(bodyParser.urlencoded({
    extended: true,
    verify: function(req, res, buffer) {
      if (!req.get('x-hub-signature'))
        throw new Error('No X-Hub-Signature found on request');

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

      var signature = req.get('x-hub-signature');
      var computedSignature = signBlob(secret, buffer);

      console.log('verified', signature, computedSignature);

      if (signature !== computedSignature) {
        console.warn('Recieved an invalid HMAC: calculated:' +
          computedSignature + ' != recieved:' + signature);
        throw new Error('Invalid Signature');
      }
    }
  }));

  app.get('/', (req, res) => {
    res.status(200).send('pong!');
  });

  app.post('/ghwebook', (req, res) => {
    const event = req.get('x-github-event');
    try {
      const payload = JSON.parse(req.body.payload);
      eventEmitter.emit(event, payload);
      res.status(200).send('ok');
    }
    catch (ex) {
      res.status(500).send(ex);
    }

{'fraction_non_alphanumeric': 0.1709653647752395, 'fraction_numerical': 0.007000736919675755, 'mean_word_length': 3.2621664050235477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1818264', 'n_tokens_mistral': 845, 'n_tokens_neox': 822, 'n_words': 184}