<commit_before>#!/usr/bin/env node
'use strict';

var bodyParser = require('body-parser');
var bunyan = require('bunyan');
var express = require('express');
var octokat = require('octokat');
var superagent = require('superagent-promise')(require('superagent'), Promise);

// ignore errors for git's SSL certificate 
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;

var log = bunyan.createLogger({ name: 'app' });
var app = express();
app.use(bodyParser.json());
var github = new octokat({
  token: process.env.GITHUB_TOKEN,
  rootURL: 'https://git/api/v3'
})

log.info('Starting');

app.get('/',  function (req, res) {
  res.send('leeroy-pull-request-builder');
});

app.post('/event_handler', function (req, res) {
  var gitHubEvent = req.headers['x-github-event'];
  log.info('Received GitHub event: ' + gitHubEvent);
  if (gitHubEvent === 'ping') {
    res.status(204).send();
  } else if (gitHubEvent === 'pull_request') {
    if (req.body.action === 'opened' || req.body.action === 'reopened' || req.body.action === 'synchronize') {
      var pr = req.body.pull_request;
      processPullRequest(pr)
        .then(null, function (e) {
          log.error(e);
          setStatus(pr.base.repo.owner.login, pr.base.repo.name, pr.head.sha, 'error', 'Error creating CI build');
        });
      res.status(204).send();
    }    
  } else {
    res.status(400).send();
  }
});

app.post('/jenkins', function (req, res) {
  log.info('Received Jenkins notification.');
  if (req.body && req.body.build) {
    var pr = activeBuilds[req.body.build.parameters.sha1];
    if (pr) {
      switch (req.body.build.phase) {
        case 'STARTED':
          setStatus(pr.baseUser, pr.baseRepo, pr.sha, 'pending', 'Building with Jenkins', req.body.build.full_url);
          break;
        case 'COMPLETED':
          setStatus(pr.baseUser, pr.baseRepo, pr.sha,
            req.body.build.status == 'SUCCESS' ? 'success' : 'failure',
            'Jenkins build status: ' + req.body.build.status,
            req.body.build.full_url);<commit_msg>Set the Jenkins job description.<commit_after>#!/usr/bin/env node
'use strict';

var bodyParser = require('body-parser');
var bunyan = require('bunyan');
var express = require('express');
var octokat = require('octokat');
var superagent = require('superagent-promise')(require('superagent'), Promise);

// ignore errors for git's SSL certificate 
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;

var log = bunyan.createLogger({ name: 'app' });
var app = express();
app.use(bodyParser.json());
var github = new octokat({
  token: process.env.GITHUB_TOKEN,
  rootURL: 'https://git/api/v3'
})

log.info('Starting');

app.get('/',  function (req, res) {
  res.send('leeroy-pull-request-builder');
});

app.post('/event_handler', function (req, res) {
  var gitHubEvent = req.headers['x-github-event'];
  log.info('Received GitHub event: ' + gitHubEvent);
  if (gitHubEvent === 'ping') {
    res.status(204).send();
  } else if (gitHubEvent === 'pull_request') {
    if (req.body.action === 'opened' || req.body.action === 'reopened' || req.body.action === 'synchronize') {
      var pr = req.body.pull_request;
      processPullRequest(pr)
        .then(null, function (e) {
          log.error(e);
          setStatus(pr.base.repo.owner.login, pr.base.repo.name, pr.head.sha, 'error', 'Error creating CI build');
        });
      res.status(204).send();
    }    
  } else {
    res.status(400).send();
  }
});

app.post('/jenkins', function (req, res) {
  log.info('Received Jenkins notification.');
  if (req.body && req.body.build) {
    var pr = activeBuilds[req.body.build.parameters.sha1];
    if (pr) {
      switch (req.body.build.phase) {
        case 'STARTED':
          setStatus(pr.baseUser, pr.baseRepo, pr.sha, 'pending', 'Building with Jenkins', req.body.build.full_url);
          superagent.post(req.body.build.full_url + '/submitDescription')
            .type('form')
            .send({
              description: pr.title,
              Submit: 'Submit' 
            })
            .end();
          break;
        case 'COMPLETED':
          setStatus(pr.baseUser, pr.baseRepo, pr.sha,
            req.body.build.status == 'SUCCESS' ? 'success' : 'failure',
            'Jenkins build status: ' + req.body.build.status,
            req.body.build.full_url);
{'fraction_non_alphanumeric': 0.17567881178927824, 'fraction_numerical': 0.005569737758180552, 'mean_word_length': 3.0622054665409992, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1246446', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1428, 'n_words': 288}