From ab1a4760ed5b35cf58fc6f3f4e3c31be4cff17f2 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Mon, 22 Sep 2014 14:31:12 +0200 Subject: Basic prototype to handle Github webhooks --- app/Controller/Webhook.php | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 app/Controller/Webhook.php (limited to 'app/Controller/Webhook.php') diff --git a/app/Controller/Webhook.php b/app/Controller/Webhook.php new file mode 100644 index 00000000..8a81a0c4 --- /dev/null +++ b/app/Controller/Webhook.php @@ -0,0 +1,61 @@ +config->get('webhooks_token') !== $this->request->getStringParam('token')) { + $this->response->text('Not Authorized', 401); + } + + $defaultProject = $this->project->getFirst(); + + $values = array( + 'title' => $this->request->getStringParam('title'), + 'description' => $this->request->getStringParam('description'), + 'color_id' => $this->request->getStringParam('color_id'), + 'project_id' => $this->request->getIntegerParam('project_id', $defaultProject['id']), + 'owner_id' => $this->request->getIntegerParam('owner_id'), + 'column_id' => $this->request->getIntegerParam('column_id'), + 'category_id' => $this->request->getIntegerParam('category_id'), + ); + + list($valid,) = $this->taskValidator->validateCreation($values); + + if ($valid && $this->task->create($values)) { + $this->response->text('OK'); + } + + $this->response->text('FAILED'); + } + + /** + * Handle Github webhooks + * + * @access public + */ + public function github() + { + if ($this->config->get('webhooks_token') !== $this->request->getStringParam('token')) { + $this->response->text('Not Authorized', 401); + } + + $this->githubWebhook->parsePayload( + $this->request->getHeader('X-Github-Event'), + $this->request->getBody() + ); + } +} -- cgit v1.2.3