<commit_before>var express = require('express');
var nodemailer = require("nodemailer");
var settings = require('./settings');
var util = require('util');

var app = express.createServer(express.logger());

var smtp_transport = nodemailer.createTransport("SMTP",{
  service: "Gmail",
  auth: {
    user: settings.smtp_user,
    pass: settings.smtp_pass
  }
});

function check_commit(req, res) {
  var forced;
  var payload;
  var mail_opts = {
    from: settings.smtp_user,
    to: settings.recipients
  };

  res.send('cool story, bro');
  console.log(req.body);

  if (req.body && req.body.payload) {
    payload = JSON.parse(req.body.payload);
    console.log(payload);
    if (payload.forced && settings.bad_refs.indexOf(payload.ref) !== -1) {
      console.log("user", payload.pusher.name, "has forced a push to", payload.ref);

      mail_opts.subject = util.format("%s: Push forced to master", payload.repository.name);
      mail_opts.text = util.format("User %s forced a push to master in %s. Head is now at %s from %s", payload.pusher.name, payload.repository.name, payload.head_commit.id, payload.head_commit.timestamp);

      smtp_transport.sendMail(mail_opts, function(error, response) {
        if(error){
          console.log(error);
        }else{
          console.log("Message sent:", response.message);
        }
      });
    }
    else {
      console.log("no forced push. user", payload.pusher.name, "is ok.");
    }
  }
}

app.use(express.bodyParser());
app.get('/', check_commit);
app.post('/', check_commit);

console.log('listening on port', settings.port);
app.listen(settings.port);<commit_msg>Code cleanup<commit_after>var express = require("express");
var nodemailer = require("nodemailer");
var settings = require("./settings");
var util = require("util");

var app = express.createServer(express.logger());

var smtp_transport = nodemailer.createTransport("SMTP", {
  service: "Gmail",
  auth: {
    user: settings.smtp_user,
    pass: settings.smtp_pass
  }
});


function check_commit(req, res) {
  var forced;
  var payload;
  var mail_opts = {
    from: settings.smtp_user,
    to: settings.recipients
  };

  res.send("cool story, bro");
  console.log(req.body);

  if (!req.body || !req.body.payload) {
    console.log("No request.");
    return;
  }

  payload = JSON.parse(req.body.payload);
  console.log(payload);

  if (!payload) {
    console.log("No payload or error parsing it.");
    return;
  }
  if (!payload.forced) {
    console.log("Push wasn't forced.");
    return;
  }
  if (settings.bad_refs.indexOf(payload.ref) === -1) {
    console.log("Push wasn't forced. User", payload.pusher.name, "is ok.");
    return;
  }

  console.log("User", payload.pusher.name, "has forced a push to", payload.ref);

  mail_opts.subject = util.format("%s: Push forced to master", payload.repository.name);
  mail_opts.text = util.format("User %s forced a push to ref %s in repo %s. Head is now at %s from %s. Compare at %s", payload.pusher.name, payload.ref, payload.repository.name, payload.head_commit.url, payload.head_commit.timestamp, payload.compare);

  smtp_transport.sendMail(mail_opts, function(error, response) {
    if (error) {
      console.log(error);
    }
    else{
      console.log("Message sent:", response.message);
    }
  });
}


app.use(express.bodyParser());
app.get("/", check_commit);
app.post("/", check_commit);

console.log("Listening on port", settings.port);
app.listen(settings.port);
{'fraction_non_alphanumeric': 0.16025455597338734, 'fraction_numerical': 0.0005785363031530228, 'mean_word_length': 3.679296346414073, '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': '1236863', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1121, 'n_words': 255}