From 6f94ce6af3072543ee62d64016931ed424f800a7 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 8 Feb 2015 21:13:59 -0500 Subject: Add Bitbucket webhook --- app/Integration/BitbucketWebhook.php | 98 ++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 app/Integration/BitbucketWebhook.php (limited to 'app/Integration/BitbucketWebhook.php') diff --git a/app/Integration/BitbucketWebhook.php b/app/Integration/BitbucketWebhook.php new file mode 100644 index 00000000..9f82d5c0 --- /dev/null +++ b/app/Integration/BitbucketWebhook.php @@ -0,0 +1,98 @@ +project_id = $project_id; + } + + /** + * Parse events + * + * @access public + * @param array $payload Gitlab event + * @return boolean + */ + public function parsePayload(array $payload) + { + if (! empty($payload['commits'])) { + + foreach ($payload['commits'] as $commit) { + + if ($this->handleCommit($commit)) { + return true; + } + } + } + + return false; + } + + /** + * Parse commit + * + * @access public + * @param array $commit Gitlab commit + * @return boolean + */ + public function handleCommit(array $commit) + { + $task_id = $this->task->getTaskIdFromText($commit['message']); + + if (! $task_id) { + return false; + } + + $task = $this->taskFinder->getById($task_id); + + if (! $task) { + return false; + } + + if ($task['is_active'] == Task::STATUS_OPEN && $task['project_id'] == $this->project_id) { + + $this->container['dispatcher']->dispatch( + self::EVENT_COMMIT, + new TaskEvent(array('task_id' => $task_id) + $task) + ); + + return true; + } + + return false; + } +} -- cgit v1.2.3