<commit_before>module.exports = function () {
	var express = require('express');
	var bodyParser = require('body-parser');
	var Request = require('request');
	var basicAuth = require('basic-auth-connect');
	var app = express();

	app.use('/media', express.static(__dirname + '/media'));
	app.use(bodyParser.json());
	app.set('view engine', 'ejs');
	app.enable('trust proxy');

	app.get('/', function (req, res) {
		Request({
			url: 'https://' + process.env.BITBUCKET_USERNAME + ':' + process.env.BITBUCKET_PASSWORD + '@api.bitbucket.org/2.0/users/chesleybrown',
			method: 'GET'
		}, function (err, response, body) {
			res.render('index', {
				BITBUCKET_USERNAME: process.env.BITBUCKET_USERNAME,
				BITBUCKET_PASSWORD: Boolean(process.env.BITBUCKET_PASSWORD),
				ssl: (req.protocol === 'https') ? true : false,
				host: req.get('host'),
				authenticated: (err || response.statusCode !== 200) ? false : true
			});
		});
	});

	app.post('/pull-request/:codeshipProjectUuid/:codeshipProjectId', basicAuth(function (username, password) {
		return (username === process.env.BITBUCKET_USERNAME && password === process.env.BITBUCKET_PASSWORD);
	}), function (req, res) {
		if (Object.keys(req.body).length === 0) {
			console.log('Body is not found');
			res.status(400).end();
			return;
		}

		// verify we have the information we need
		if (!req.body.pullrequest_created) {
			console.log('pullrequest_created is not found');
			console.log(req.body);
			res.status(400).end();
			return;
		}
		var pullRequest = req.body.pullrequest_created;

		if (!pullRequest.id || typeof(pullRequest.description) !== 'string' || !(pullRequest.source && pullRequest.source.branch && pullRequest.source.branch.name) || !(pullRequest.source && pullRequest.source.repository && pullRequest.source.repository.full_name)) {
			console.log('description | source | source.branch | soruce.branch.name | source.repository | source.repository.full_name is not found');
			console.log(req.body);
			res.status(400).end();
			return;
		}

		// if it doesn't already have Codeship status at the start of the description, let's add it
		if (pullRequest.description.indexOf('[ ![Codeship Status') !== 0) {
			var widget = '[ ![Codeship Status for ' + pullRequest.source.repository.full_name + '](https://codeship.io/projects/' + req.param('codeshipProjectUuid') +'/status?branch=' + pullRequest.source.branch.name + ')](https://codeship.io/projects/' + req.param('codeshipProjectId') + ')';
			pullRequest.description = widget + '\r\n\r\n' + pullRequest.description;

			Request({
				url: 'https://' + process.env.BITBUCKET_USERNAME + ':' + process.env.BITBUCKET_PASSWORD + '@api.bitbucket.org/2.0/repositories/' + pullRequest.source.repository.full_name + '/pullrequests/' + pullRequest.id,
				method: 'PUT',
				json: pullRequest
			}, function (err, response, body) {
				if (err) {
					res.status(500).end();
					return;
				}

				if (response.body && response.body.error) {
					res.status(500).end();
					return;
				}

				res.status(204).end();
			});
		}
		else {
			res.status(204).end();
		}
	});

	return app;
};
<commit_msg>Changed to look for `pullrequest` instead of `pullrequest_created` since that is what it looks like according to what BitBucket is posting<commit_after>module.exports = function () {
	var express = require('express');
	var bodyParser = require('body-parser');
	var Request = require('request');
	var basicAuth = require('basic-auth-connect');
	var app = express();

	app.use('/media', express.static(__dirname + '/media'));
	app.use(bodyParser.json());
	app.set('view engine', 'ejs');
	app.enable('trust proxy');

	app.get('/', function (req, res) {
		Request({
			url: 'https://' + process.env.BITBUCKET_USERNAME + ':' + process.env.BITBUCKET_PASSWORD + '@api.bitbucket.org/2.0/users/chesleybrown',
			method: 'GET'
		}, function (err, response, body) {
			res.render('index', {
				BITBUCKET_USERNAME: process.env.BITBUCKET_USERNAME,
				BITBUCKET_PASSWORD: Boolean(process.env.BITBUCKET_PASSWORD),
				ssl: (req.protocol === 'https') ? true : false,
				host: req.get('host'),
				authenticated: (err || response.statusCode !== 200) ? false : true
			});
		});
	});

	app.post('/pull-request/:codeshipProjectUuid/:codeshipProjectId', basicAuth(function (username, password) {
		return (username === process.env.BITBUCKET_USERNAME && password === <PASSWORD>.BITBUCKET_PASSWORD);
	}), function (req, res) {
		if (Object.keys(req.body).length === 0) {
			console.log('Body is not found');
			res.status(400).end();
			return;
		}

		// verify we have the information we need
		if (!req.body.pullrequest) {
			console.log('pullrequest is not found');
			console.log(req.body);
			res.status(400).end();
			return;
		}
		var pullRequest = req.body.pullrequest;

		if (!pullRequest.id || typeof(pullRequest.description) !== 'string' || !(pullRequest.source && pullRequest.source.branch && pullRequest.source.branch.name) || !(pullRequest.source && pullRequest.source.repository && pullRequest.source.repository.full_name)) {
			console.log('description | source | source.branch | soruce.branch.name | source.repository | source.repository.full_name is not found');
			console.log(pullRequest);
			res.status(400).end();
			return;
		}

		// if it doesn't already have Codeship status at the start of the description, let's add it
		if (pullRequest.description.indexOf('[ ![Codeship Status') !== 0) {
			var widget = '[ ![Codeship Status for ' + pullRequest.source.repository.full_name + '](https://codeship.io/projects/' + req.param('codeshipProjectUuid') +'/status?branch=' + pullRequest.source.branch.name + ')](https://codeship.io/projects/' + req.param('codeshipProjectId') + ')';
			pullRequest.description = widget + '\r\n\r\n' + pullRequest.description;

			Request({
				url: 'https://' + process.env.BITBUCKET_USERNAME + ':' + process.env.BITBUCKET_PASSWORD + '@api.bitbucket.org/2.0/repositories/' + pullRequest.source.repository.full_name + '/pullrequests/' + pullRequest.id,
				method: 'PUT',
				json: pullRequest
			}, function (err, response, body) {
				if (err) {
					res.status(500).end();
					return;
				}

				if (response.body && response.body.error) {
					res.status(500).end();
					return;
				}

				res.status(204).end();
			});
		}
		else {
			res.status(204).end();
		}
	});

	return app;
};

{'fraction_non_alphanumeric': 0.17442043841665353, 'fraction_numerical': 0.009462229932187352, 'mean_word_length': 4.02934179222839, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 8, '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': '3116851', 'n_tokens_mistral': 2317, 'n_tokens_neox': 2042, 'n_words': 400}