<commit_before><?php namespace ShinyDeploy\Core\RequestParser;

use ShinyDeploy\Core\RequestParser\RequestParser;

class Bitbucket implements RequestParser
{
    /** @var array $parameters */
    protected $parameters = [];

    public function parseRequest()
    {
        return false;
    }

    public function getParameters()
    {
        return $this->parameters;
    }
}<commit_msg>Add branch filter for bitbucket webhooks<commit_after><?php namespace ShinyDeploy\Core\RequestParser;

use ShinyDeploy\Core\RequestParser\RequestParser;

class Bitbucket implements RequestParser
{
    /** @var array $parameters */
    protected $parameters = [];

    public function parseRequest()
    {
        if (empty($_SERVER['HTTP_USER_AGENT'])) {
            return false;
        }
        if (stripos($_SERVER['HTTP_USER_AGENT'], 'Bitbucket') === false) {
            return false;
        }

        // Unfortunatly bitbucket does not send valid POST requests so we need this hack:
        $requestData = file_get_contents('php://input');
        if (empty($requestData)) {
            return false;
        }
        $requestParams = json_decode($requestData, true);
        if (empty($requestParams)) {
            return false;
        }

        // fetch branch name
        if (!empty($requestParams['push']['changes'][0]['new']['name'])) {
            $branchParts = explode('/', $requestParams['push']['changes'][0]['new']['name']);
            $this->parameters['branch'] = array_pop($branchParts);
        }

        // fetch revision hash
        if (!empty($requestParams['push']['changes'][0]['new']['target']['hash'])) {
            $this->parameters['revision'] = $requestParams['push']['changes'][0]['new']['target']['hash'];
        }

        return true;
    }

    public function getParameters()
    {
        return $this->parameters;
    }
}
{'fraction_non_alphanumeric': 0.148068669527897, 'fraction_numerical': 0.002145922746781116, 'mean_word_length': 2.722554890219561, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3306999', 'n_tokens_mistral': 494, 'n_tokens_neox': 491, 'n_words': 106}