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/Model/GithubWebhook.php | 81 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 app/Model/GithubWebhook.php (limited to 'app/Model/GithubWebhook.php') diff --git a/app/Model/GithubWebhook.php b/app/Model/GithubWebhook.php new file mode 100644 index 00000000..688ab601 --- /dev/null +++ b/app/Model/GithubWebhook.php @@ -0,0 +1,81 @@ +parsePushEvent($payload); + case 'issues': + return $this->parseIssueEvent($payload); + } + } + + /** + * Parse Push events (list of commits) + * + * @access public + * @param array $payload Event data + */ + public function parsePushEvent(array $payload) + { + foreach ($payload['commits'] as $commit) { + + $task_id = $this->task->getTaskIdFromText($commit['message']); + + if (! $task_id) { + continue; + } + + $task = $this->task->getById($task_id); + + if (! $task) { + continue; + } + + if ($task['is_active'] == Task::STATUS_OPEN) { + $this->event->trigger(self::EVENT_COMMIT, array('task_id' => $task_id) + $task); + } + } + } + + /** + * Parse issue events + * + * @access public + * @param array $payload Event data + */ + public function parseIssueEvent(array $payload) + { + + } +} -- cgit v1.2.3