<commit_before>'use strict';

/**
 * Trello connector.
 * (C) 2015 <NAME>.
 */


// requires
require('prototypes');
var Log = require('log');
var async = require('async');
var https = require('https');
var testing = require('testing');
var credentials = require('../credentials.json');

// globals
var log = new Log('info');

// constants

exports.Board = function(options)
{
	// self-reference
	var self = this;

	self.createCard = function(name, description, listId, callback)
	{
		var variables = {
			name: name,
			desc: description,
			labels: 'orange',
		};
		var path = '/1/lists/' + listId + '/cards';
		makeRequest(path, 'POST', variables, callback);
	};

	function makeRequest(path, method, variables, callback)
	{
		variables.token = options.token;
		variables.key = options.key;
		var params = {
			host: 'trello.com',
			path: path + '?' + convert(variables),
			method: method,
			agent: false,
		};
		var request = https.request(params, function(response)
		{
			if (response.statusCode != 200)
			{
				return callback('Invalid response for ' + params.path + ': ' + response.statusCode);
			}
			var body = '';
			response.on('data', function(data)
			{
				body += String(data);
			});
			response.on('error', function(error)
			{
				callback('Could not listen to response: ' + error);
			});
			response.on('end', function()
			{
				var json;
				try
				{
					json = JSON.parse(body);
				}
				catch(exception)
				{
					return callback('Could not parse JSON: ' + exception);
				}
				return callback(null, json);
			});
		});
		request.end();
		request.on('error', function(error)
		{
			callback('Could not connect to ' + path + ': ' + error);
		});
	}

	function convert(map)
	{
		var results = [];
		for (var key in map)
		{
			results.push(key + '=' + encodeURIComponent(map[key]));
		}
		return results.join('&');
	}

	self.readList = function(listId, callback)
	{
		var path = '/1/lists/' + listId;
		makeRequest(path, 'GET', {cards: 'all'}, callback);
	};

	self.findCard = function(name, callback)
	{
		readBoard(function(error, board)
		{
			if (error)
			{
				return callback(error);
			}
			var tasks = board.lists.map(function(list)
			{
				return function(callback)
				{
					self.readList(list.id, callback);
				};
			});
			async.series(tasks, function(error, lists)
			{
				if (error)
				{
					return callback(error);
				}
				var matchingCards = lists.map(function(list)
				{
					var matchingInList = list.cards.filter(function(card)
					{
						return card.name.startsWith(name);
					});
					if (matchingInList.length)
					{
						return matchingInList[0];
					}
					return null;
				}).filter(function(matchingCard)
				{
					return matchingCard;
				});
				return callback(null, matchingCards[0]);
			});
		});
	};

	/**
	 * Returns an array of comments for a card, including text and author.
	 */
	self.readComments = function(cardId, callback)
	{
		var path = '/1/cards/' + cardId + '/actions';
		makeRequest(path, 'GET', {filter: 'commentCard'}, function(error, results)
		{
			if (error)
			{
				return error;
			}
			var comments = results.map(function(commentCard)
			{
				return {
					text: commentCard.data.text,
					date: commentCard.date,
					author: commentCard.memberCreator,
				};
			});
			callback(null, comments);
		});
	};

	self.moveCard = function(title, listId, callback)
	{
		if (title.length == 14 && !title.contains('['))
		{
			return moveCardId(title, listId, callback);
		}
		self.findCard(title, function(error, card)
		{
			if (error)
			{
				return callback(error);
			}
			moveCardId(card.id, listId, callback);
		});<commit_msg>Do not move card if not found.<commit_after>'use strict';

/**
 * Trello connector.
 * (C) 2015 <NAME>.
 */


// requires
require('prototypes');
var Log = require('log');
var async = require('async');
var https = require('https');
var testing = require('testing');
var credentials = require('../credentials.json');

// globals
var log = new Log('info');

// constants

exports.Board = function(options)
{
	// self-reference
	var self = this;

	self.createCard = function(name, description, listId, callback)
	{
		var variables = {
			name: name,
			desc: description,
			labels: 'orange',
		};
		var path = '/1/lists/' + listId + '/cards';
		makeRequest(path, 'POST', variables, callback);
	};

	function makeRequest(path, method, variables, callback)
	{
		variables.token = options.token;
		variables.key = options.key;
		var params = {
			host: 'trello.com',
			path: path + '?' + convert(variables),
			method: method,
			agent: false,
		};
		var request = https.request(params, function(response)
		{
			if (response.statusCode != 200)
			{
				return callback('Invalid response for ' + params.path + ': ' + response.statusCode);
			}
			var body = '';
			response.on('data', function(data)
			{
				body += String(data);
			});
			response.on('error', function(error)
			{
				callback('Could not listen to response: ' + error);
			});
			response.on('end', function()
			{
				var json;
				try
				{
					json = JSON.parse(body);
				}
				catch(exception)
				{
					return callback('Could not parse JSON: ' + exception);
				}
				return callback(null, json);
			});
		});
		request.end();
		request.on('error', function(error)
		{
			callback('Could not connect to ' + path + ': ' + error);
		});
	}

	function convert(map)
	{
		var results = [];
		for (var key in map)
		{
			results.push(key + '=' + encodeURIComponent(map[key]));
		}
		return results.join('&');
	}

	self.readList = function(listId, callback)
	{
		var path = '/1/lists/' + listId;
		makeRequest(path, 'GET', {cards: 'all'}, callback);
	};

	self.findCard = function(name, callback)
	{
		readBoard(function(error, board)
		{
			if (error)
			{
				return callback(error);
			}
			var tasks = board.lists.map(function(list)
			{
				return function(callback)
				{
					self.readList(list.id, callback);
				};
			});
			async.series(tasks, function(error, lists)
			{
				if (error)
				{
					return callback(error);
				}
				var matchingCards = lists.map(function(list)
				{
					var matchingInList = list.cards.filter(function(card)
					{
						return card.name.startsWith(name);
					});
					if (matchingInList.length)
					{
						return matchingInList[0];
					}
					return null;
				}).filter(function(matchingCard)
				{
					return matchingCard;
				});
				return callback(null, matchingCards[0]);
			});
		});
	};

	/**
	 * Returns an array of comments for a card, including text and author.
	 */
	self.readComments = function(cardId, callback)
	{
		var path = '/1/cards/' + cardId + '/actions';
		makeRequest(path, 'GET', {filter: 'commentCard'}, function(error, results)
		{
			if (error)
			{
				return error;
			}
			var comments = results.map(function(commentCard)
			{
				return {
					text: commentCard.data.text,
					date: commentCard.date,
					author: commentCard.memberCreator,
				};
			});
			callback(null, comments);
		});
	};

	self.moveCard = function(title, listId, callback)
	{
		if (title.length == 14 && !title.contains('['))
		{
			return moveCardId(title, listId, callback);
		}
		self.findCard(title, function(error, card)
		{
			if (error)
			{
				return callback(error);
			}
			if (!card)
			{
				return callback('Could not find card ' + title);
			}
			moveCardId(card.id, listId, callback);
		});
{'fraction_non_alphanumeric': 0.1604132680804785, 'fraction_numerical': 0.0038064165307232192, 'mean_word_length': 2.9321218599679315, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3983525', 'n_tokens_mistral': 3027, 'n_tokens_neox': 2415, 'n_words': 540}