<commit_before><?php

namespace PHPCI\Controller;
use b8,
	b8\Store,
	PHPCI\Model\Build;


class BitbucketController extends b8\Controller
{
	public function init()
	{
		$this->_buildStore		= Store\Factory::getStore('Build');
	}

	public function webhook($project)
	{
		$payload	= json_decode($this->getParam('payload'), true);

		try
		{
			$build		= new Build();
			$build->setProjectId($project);
			$build->setCommitId($payload['after']);
			$build->setStatus(0);
			$build->setLog('');
			$build->setCreated(new \DateTime());
			$build->setBranch(str_replace('refs/heads/', '', $payload['ref']));
		}
		catch(\Exception $ex)
		{
			header('HTTP/1.1 400 Bad Request');
			header('Ex: ' . $ex->getMessage());
			die('FAIL');
		}

		try
		{
			$this->_buildStore->save($build);
		}
		catch(\Exception $ex)
		{
			header('HTTP/1.1 500 Internal Server Error');
			header('Ex: ' . $ex->getMessage());
			die('FAIL');
		}
		
		die('OK');
	}
}<commit_msg>Adding proper Bitbucket support<commit_after><?php

namespace PHPCI\Controller;
use b8,
	b8\Store,
	PHPCI\Model\Build;


class BitbucketController extends b8\Controller
{
	public function init()
	{
		$this->_buildStore		= Store\Factory::getStore('Build');
	}

	public function webhook($project)
	{
		$payload	= json_decode(file_get_contents('php://input'), true);
		$branches	= array();
		$commits	= array();

		foreach($payload['commits'] as $commit)
		{
			if(!in_array($commit['branch'], $branches))
			{
				$branches[]					= $commit['branch'];
				$commits[$commit['branch']]	= $commit['raw_node'];
			}
		}

		foreach($branches as $branch)
		{
			try
			{

				$build		= new Build();
				$build->setProjectId($project);
				$build->setCommitId($commits[$branch]);
				$build->setStatus(0);
				$build->setLog('');
				$build->setCreated(new \DateTime());
				$build->setBranch($branch);
				$this->_buildStore->save($build);
			}
			catch(\Exception $ex)
			{
			}
		}
		
		die('OK');
	}
}
{'fraction_non_alphanumeric': 0.19722650231124808, 'fraction_numerical': 0.009244992295839754, 'mean_word_length': 3.7745098039215685, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '2258921', 'n_tokens_mistral': 816, 'n_tokens_neox': 694, 'n_words': 112}