<commit_before>// The hubot for <NAME>, the monkey king.
// Sun is responsible for listening to deploy commands:
//    sun, deploy branch foo
// etc.

var http = require('http');


var runDeployOnJenkins = function(robot, deployBranch, caller) {
    var options = {
        hostname: 'jenkins.khanacademy.org',
        port: 80,
        path: '/buildByToken/buildWithParameters',
        method: 'POST'
    };

    var req = http.request(options, function(res) {});

    req.on('error', function(e) {
        var hipchatMessage = {
            msg: ("(sadpanda) Jenkins won't listen to me.  " +
                  "Go talk to it yourself."),
            color: "red",
            room: "1s/0s: deploys",
            from: "<NAME>",
        };
        robot.fancyMessage(hipchatMessage);
    });

    // write data to request body
    req.write("job=deploy-via-multijob" +
              "&token=" + process.env.JENKINS_DEPLOY_TOKEN +
              "&GIT_REVISION=" + deployBranch +
              // In theory this should be an email address but we
              // actually only care about hipchat names for the
              // script, so we make up a 'fake' email that yields our
              // hipchat name.
              "&BUILD_USER_ID_FROM_SCRIPT=" + caller + "@khanacademy.org" +
              "&cause=Sun+Wukong\n");
    req.end();
};


module.exports = function(robot) {
  robot.hear(/^sun,\s+deploy\s+(?:branch\s+)?(.*)$/i, function(msg) {
      var text;
      var deployBranch = null;
      if (msg.envelope.room === '1s0s_deploys') {
          deployBranch = msg.match[1];
          text = "Telling Jenkins to deploy branch " + deployBranch;
      } else {
          text = "How dare you approach me outside my temple?!";
      }
      var hipchatMessage = {
          msg: text,
          color: "purple",
          room: msg.envelope.room,
          from: "<NAME>",
      };
      robot.fancyMessage(hipchatMessage);

      if (deployBranch) {<commit_msg>Apparently nginx needs a content-length, so get nodejs to send one.<commit_after>// The hubot for <NAME>, the monkey king.
// Sun is responsible for listening to deploy commands:
//    sun, deploy branch foo
// etc.

var http = require('http');


var runDeployOnJenkins = function(robot, deployBranch, caller) {
    var postData = ("job=deploy-via-multijob" +
                    "&token=" + process.env.JENKINS_DEPLOY_TOKEN +
                    "&GIT_REVISION=" + deployBranch +
                    // In theory this should be an email address but
                    // we actually only care about hipchat names for
                    // the script, so we make up a 'fake' email that
                    // yields our hipchat name.
                    "&BUILD_USER_ID_FROM_SCRIPT=" +
                    caller + "@khanacademy.org" +
                    "&cause=Sun+Wukong\n");

    var options = {
        hostname: 'jenkins.khanacademy.org',
        port: 80,
        path: '/buildByToken/buildWithParameters',
        method: 'POST'
    };

    var errorMessage = {
        msg: ("(sadpanda) Jenkins won't listen to me.  " +
              "Go talk to it yourself."),
        color: "red",
        room: "1s/0s: deploys",
        from: "<NAME>",
    };

    var req = http.request(options, function(res) {
        if (res.statusCode !== 200) {
            robot.fancyMessage(errorMessage);
        }
    });

    req.on('error', function(e) {
        robot.fancyMessage(errorMessage);
    });

    // write data to request body
    req.setHeader('Content-length', postData.length);
    req.write(postData);
    req.end();
};


module.exports = function(robot) {
  robot.hear(/^sun,\s+deploy\s+(?:branch\s+)?(.*)$/i, function(msg) {
      var text;
      var deployBranch = null;
      if (msg.envelope.room === '1s0s_deploys') {
          deployBranch = msg.match[1];
          text = "Telling Jenkins to deploy branch " + deployBranch;
      } else {
          text = "How dare you approach me outside my temple?!";
      }
      var hipchatMessage = {
          msg: text,
          color: "purple",
          room: msg.envelope.room,
          from: "<NAME>",
      };
      robot.fancyMessage(hipchatMessage);

      if (deployBranch) {
{'fraction_non_alphanumeric': 0.13045540796963948, 'fraction_numerical': 0.004032258064516129, 'mean_word_length': 1.9244105409153953, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '7609240', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1281, 'n_words': 333}