<commit_before><?php
namespace Criterion\UI\Controller;

class HookController
{
    public function github(\Silex\Application $app)
    {
        $payload = json_decode($app['request']->get('payload'), true);
        if ( ! isset($payload['repository']['url']))
        {
            return $app->json(array(
                'success' => false
            ));
        }

        $repo = $payload['repository']['url'];
        // Detect if its an private repository, if so then we need to use SSH
        if ($payload['repository']['private'])
        {
            $repo = \Criterion\Helper\Github::toSSHUrl($repo);
        }

        $project = new \Criterion\Model\Project(array(
            'repo' => $repo
        ));

        if ( ! $project->exists)
        {
            $project->save();
        }

        $test = new \Criterion\Model\Test();
        $test->project_id = $project->id;
        $test->branch = str_replace('refs/heads/', null, $payload['ref']);
        $test->save();

        return $app->json(array(
            'success' => true,
            'test' => (string) $test->id
        ));
    }
}
<commit_msg>Use token in github hook<commit_after><?php
namespace Criterion\UI\Controller;

class HookController
{
    public function github(\Silex\Application $app)
    {
        $query_token = $app['request']->query->get('token');

        $token = new \Criterion\Model\Token($query_token);

        if ( ! $token->exists)
        {
            return $app->abort(404, 'Page does not exist');
        }


        $payload = json_decode($app['request']->get('payload'), true);
        if ( ! isset($payload['repository']['url']))
        {
            return $app->json(array(
                'success' => false
            ));
        }

        $repo = $payload['repository']['url'];
        // Detect if its an private repository, if so then we need to use SSH
        if ($payload['repository']['private'])
        {
            $repo = \Criterion\Helper\Github::toSSHUrl($repo);
        }

        $project = new \Criterion\Model\Project(array(
            'repo' => $repo
        ));

        if ( ! $project->exists)
        {
            $project->save();
        }

        $test = new \Criterion\Model\Test();
        $test->project_id = $project->id;
        $test->branch = str_replace('refs/heads/', null, $payload['ref']);
        $test->save();

        return $app->json(array(
            'success' => true,
            'test' => (string) $test->id
        ));
    }
}

{'fraction_non_alphanumeric': 0.16999201915403034, 'fraction_numerical': 0.0011971268954509178, 'mean_word_length': 1.8456299659477866, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '125469', 'n_tokens_mistral': 724, 'n_tokens_neox': 714, 'n_words': 143}