/**
  * Handle Gogs webhooks
  *
  * @access public
  */
 public function handler()
 {
     $this->checkWebhookToken();
     $handler = new WebhookHandler($this->container);
     $handler->setProjectId($this->request->getIntegerParam('project_id'));
     $result = $handler->parsePayload($this->request->getHeader('X-Gogs-Event'), $this->request->getJson());
     $this->response->text($result ? 'PARSED' : 'IGNORED');
 }
 public function testHandlePush()
 {
     $this->container['dispatcher']->addListener(WebhookHandler::EVENT_COMMIT, array($this, 'onCommit'));
     $tc = new TaskCreationModel($this->container);
     $p = new ProjectModel($this->container);
     $handler = new WebhookHandler($this->container);
     $payload = json_decode(file_get_contents(__DIR__ . '/fixtures/push.json'), true);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $handler->setProjectId(1);
     // No task
     $this->assertFalse($handler->parsePayload('push', $payload));
     // Create task with the wrong id
     $this->assertEquals(1, $tc->create(array('title' => 'test1', 'project_id' => 1)));
     $this->assertFalse($handler->parsePayload('push', $payload));
     // Create task with the right id
     $this->assertEquals(2, $tc->create(array('title' => 'test2', 'project_id' => 1)));
     $this->assertTrue($handler->parsePayload('push', $payload));
     $called = $this->container['dispatcher']->getCalledListeners();
     $this->assertArrayHasKey(WebhookHandler::EVENT_COMMIT . '.WebhookHandlerTest::onCommit', $called);
 }