<commit_before><?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class WebhookController extends Controller
{
    /**
     * @Route("/webhooks/github", name="webhooks_github")
     * @Method("POST")
     */
    public function githubAction(Request $request)
    {
        $data = json_decode($request->getContent(), true);
        if ($data === null) {
            throw new \Exception('Invalid JSON body!');
        }

        $event = $request->headers->get('X-Github-Event');

        switch ($event) {
            case 'issue_comment':
                $responseData = $this->handleIssueCommentEvent($data);
                break;
            default:
                $responseData = [
                    'unsupported_event' => $event
                ];
        }

        return new JsonResponse($responseData);

        // 1 read in what event they have
        // 2 perform some action
        // 3 return JSON

        // log something to the database?
    }

    private function handleIssueCommentEvent(array $data)
    {
        $commentText = $data['comment']['body'];
        $issueNumber = $data['issue']['number'];

        $newStatus = $this->get('app.github.status_manager')
            ->getStatusChangeFromComment($commentText);

        // hacky way to not actually try to talk to GitHub when testing
        if ($this->container->getParameter('kernel.environment') == 'test') {
            $this->get('app.issue_status_changer')
                ->setIssueStatusLabel($issueNumber, $newStatus);
        }

        return [
            'issue' => $issueNumber,
            'status_change' => $newStatus,
        ];<commit_msg>whoops - changing my backwards logic<commit_after><?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class WebhookController extends Controller
{
    /**
     * @Route("/webhooks/github", name="webhooks_github")
     * @Method("POST")
     */
    public function githubAction(Request $request)
    {
        $data = json_decode($request->getContent(), true);
        if ($data === null) {
            throw new \Exception('Invalid JSON body!');
        }

        $event = $request->headers->get('X-Github-Event');

        switch ($event) {
            case 'issue_comment':
                $responseData = $this->handleIssueCommentEvent($data);
                break;
            default:
                $responseData = [
                    'unsupported_event' => $event
                ];
        }

        return new JsonResponse($responseData);

        // 1 read in what event they have
        // 2 perform some action
        // 3 return JSON

        // log something to the database?
    }

    private function handleIssueCommentEvent(array $data)
    {
        $commentText = $data['comment']['body'];
        $issueNumber = $data['issue']['number'];

        $newStatus = $this->get('app.github.status_manager')
            ->getStatusChangeFromComment($commentText);

        // hacky way to not actually try to talk to GitHub when testing
        if ($this->container->getParameter('kernel.environment') != 'test') {
            $this->get('app.issue_status_changer')
                ->setIssueStatusLabel($issueNumber, $newStatus);
        }

        return [
            'issue' => $issueNumber,
            'status_change' => $newStatus,
        ];
{'fraction_non_alphanumeric': 0.12347283597608526, 'fraction_numerical': 0.0015596568754873928, 'mean_word_length': 2.3258426966292136, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '1207411', 'n_tokens_mistral': 1021, 'n_tokens_neox': 982, 'n_words': 212}