diff --git a/README.markdown b/README.markdown index 21f2ebe93..9b012ad0d 100644 --- a/README.markdown +++ b/README.markdown @@ -86,6 +86,7 @@ Documentation ### Integrations +- [Bitbucket webhooks](docs/bitbucket-webhooks.markdown) - [Github webhooks](docs/github-webhooks.markdown) - [Gitlab webhooks](docs/gitlab-webhooks.markdown) diff --git a/app/Action/TaskClose.php b/app/Action/TaskClose.php index 760dfd840..b7cd4dbf3 100644 --- a/app/Action/TaskClose.php +++ b/app/Action/TaskClose.php @@ -4,6 +4,7 @@ namespace Action; use Integration\GitlabWebhook; use Integration\GithubWebhook; +use Integration\BitbucketWebhook; use Model\Task; /** @@ -28,6 +29,7 @@ class TaskClose extends Base GithubWebhook::EVENT_ISSUE_CLOSED, GitlabWebhook::EVENT_COMMIT, GitlabWebhook::EVENT_ISSUE_CLOSED, + BitbucketWebhook::EVENT_COMMIT, ); } @@ -44,6 +46,7 @@ class TaskClose extends Base case GithubWebhook::EVENT_ISSUE_CLOSED: case GitlabWebhook::EVENT_COMMIT: case GitlabWebhook::EVENT_ISSUE_CLOSED: + case BitbucketWebhook::EVENT_COMMIT: return array(); default: return array('column_id' => t('Column')); @@ -63,6 +66,7 @@ class TaskClose extends Base case GithubWebhook::EVENT_ISSUE_CLOSED: case GitlabWebhook::EVENT_COMMIT: case GitlabWebhook::EVENT_ISSUE_CLOSED: + case BitbucketWebhook::EVENT_COMMIT: return array('task_id'); default: return array('task_id', 'column_id'); @@ -95,6 +99,7 @@ class TaskClose extends Base case GithubWebhook::EVENT_ISSUE_CLOSED: case GitlabWebhook::EVENT_COMMIT: case GitlabWebhook::EVENT_ISSUE_CLOSED: + case BitbucketWebhook::EVENT_COMMIT: return true; default: return $data['column_id'] == $this->getParam('column_id'); diff --git a/app/Controller/Webhook.php b/app/Controller/Webhook.php index 1ae3b0a41..ef79379f5 100644 --- a/app/Controller/Webhook.php +++ b/app/Controller/Webhook.php @@ -82,4 +82,22 @@ class Webhook extends Base echo $result ? 'PARSED' : 'IGNORED'; } + + /** + * Handle Bitbucket webhooks + * + * @access public + */ + public function bitbucket() + { + if ($this->config->get('webhook_token') !== $this->request->getStringParam('token')) { + $this->response->text('Not Authorized', 401); + } + + $this->bitbucketWebhook->setProjectId($this->request->getIntegerParam('project_id')); + + $result = $this->bitbucketWebhook->parsePayload(json_decode(@$_POST['payload'], true)); + + echo $result ? 'PARSED' : 'IGNORED'; + } } diff --git a/app/Integration/BitbucketWebhook.php b/app/Integration/BitbucketWebhook.php new file mode 100644 index 000000000..9f82d5c07 --- /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; + } +} diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php index 07c05b895..fbd7b3ab4 100644 --- a/app/Locale/da_DK/translations.php +++ b/app/Locale/da_DK/translations.php @@ -678,4 +678,7 @@ return array( // 'Disable login form' => '', // 'Show/hide calendar' => '', // 'User calendar' => '', + // 'Bitbucket commit received' => '', + // 'Bitbucket webhooks' => '', + // 'Help on Bitbucket webhooks' => '', ); diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php index af15c6b23..b3a9c04bc 100644 --- a/app/Locale/de_DE/translations.php +++ b/app/Locale/de_DE/translations.php @@ -678,4 +678,7 @@ return array( // 'Disable login form' => '', // 'Show/hide calendar' => '', // 'User calendar' => '', + // 'Bitbucket commit received' => '', + // 'Bitbucket webhooks' => '', + // 'Help on Bitbucket webhooks' => '', ); diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php index b39e97933..8cfa91b8d 100644 --- a/app/Locale/es_ES/translations.php +++ b/app/Locale/es_ES/translations.php @@ -678,4 +678,7 @@ return array( // 'Disable login form' => '', // 'Show/hide calendar' => '', // 'User calendar' => '', + // 'Bitbucket commit received' => '', + // 'Bitbucket webhooks' => '', + // 'Help on Bitbucket webhooks' => '', ); diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php index 9adc19e4b..39676bf10 100644 --- a/app/Locale/fi_FI/translations.php +++ b/app/Locale/fi_FI/translations.php @@ -678,4 +678,7 @@ return array( // 'Disable login form' => '', // 'Show/hide calendar' => '', // 'User calendar' => '', + // 'Bitbucket commit received' => '', + // 'Bitbucket webhooks' => '', + // 'Help on Bitbucket webhooks' => '', ); diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php index 2542a6fea..5df398094 100644 --- a/app/Locale/fr_FR/translations.php +++ b/app/Locale/fr_FR/translations.php @@ -680,4 +680,7 @@ return array( 'Disable login form' => 'Désactiver le formulaire d\'authentification', 'Show/hide calendar' => 'Afficher/cacher le calendrier', 'User calendar' => 'Calendrier de l\'utilisateur', + 'Bitbucket commit received' => '« Commit » reçu via Bitbucket', + 'Bitbucket webhooks' => 'Webhook Bitbucket', + 'Help on Bitbucket webhooks' => 'Aide sur les webhooks Bitbucket', ); diff --git a/app/Locale/hu_HU/translations.php b/app/Locale/hu_HU/translations.php index 8cbe6d8d0..b7fbd04e5 100644 --- a/app/Locale/hu_HU/translations.php +++ b/app/Locale/hu_HU/translations.php @@ -678,4 +678,7 @@ return array( // 'Disable login form' => '', // 'Show/hide calendar' => '', // 'User calendar' => '', + // 'Bitbucket commit received' => '', + // 'Bitbucket webhooks' => '', + // 'Help on Bitbucket webhooks' => '', ); diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php index 98ed4a91e..2a9746290 100644 --- a/app/Locale/it_IT/translations.php +++ b/app/Locale/it_IT/translations.php @@ -678,4 +678,7 @@ return array( // 'Disable login form' => '', // 'Show/hide calendar' => '', // 'User calendar' => '', + // 'Bitbucket commit received' => '', + // 'Bitbucket webhooks' => '', + // 'Help on Bitbucket webhooks' => '', ); diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php index 229622c5a..2647f9fda 100644 --- a/app/Locale/ja_JP/translations.php +++ b/app/Locale/ja_JP/translations.php @@ -678,4 +678,7 @@ return array( // 'Disable login form' => '', // 'Show/hide calendar' => '', // 'User calendar' => '', + // 'Bitbucket commit received' => '', + // 'Bitbucket webhooks' => '', + // 'Help on Bitbucket webhooks' => '', ); diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php index e2cc3ab8b..c83e130a3 100644 --- a/app/Locale/pl_PL/translations.php +++ b/app/Locale/pl_PL/translations.php @@ -678,4 +678,7 @@ return array( // 'Disable login form' => '', // 'Show/hide calendar' => '', // 'User calendar' => '', + // 'Bitbucket commit received' => '', + // 'Bitbucket webhooks' => '', + // 'Help on Bitbucket webhooks' => '', ); diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php index db640901b..0cd80f8f7 100644 --- a/app/Locale/pt_BR/translations.php +++ b/app/Locale/pt_BR/translations.php @@ -678,4 +678,7 @@ return array( // 'Disable login form' => '', // 'Show/hide calendar' => '', // 'User calendar' => '', + // 'Bitbucket commit received' => '', + // 'Bitbucket webhooks' => '', + // 'Help on Bitbucket webhooks' => '', ); diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php index 513436af9..ed68a4472 100644 --- a/app/Locale/ru_RU/translations.php +++ b/app/Locale/ru_RU/translations.php @@ -678,4 +678,7 @@ return array( // 'Disable login form' => '', // 'Show/hide calendar' => '', // 'User calendar' => '', + // 'Bitbucket commit received' => '', + // 'Bitbucket webhooks' => '', + // 'Help on Bitbucket webhooks' => '', ); diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php index 4958189fa..1d793b35e 100644 --- a/app/Locale/sv_SE/translations.php +++ b/app/Locale/sv_SE/translations.php @@ -678,4 +678,7 @@ return array( // 'Disable login form' => '', // 'Show/hide calendar' => '', // 'User calendar' => '', + // 'Bitbucket commit received' => '', + // 'Bitbucket webhooks' => '', + // 'Help on Bitbucket webhooks' => '', ); diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php index 962971f4f..cf5302f6c 100644 --- a/app/Locale/th_TH/translations.php +++ b/app/Locale/th_TH/translations.php @@ -678,4 +678,7 @@ return array( // 'Disable login form' => '', // 'Show/hide calendar' => '', // 'User calendar' => '', + // 'Bitbucket commit received' => '', + // 'Bitbucket webhooks' => '', + // 'Help on Bitbucket webhooks' => '', ); diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php index 4c76d7ab6..6dbd16768 100644 --- a/app/Locale/zh_CN/translations.php +++ b/app/Locale/zh_CN/translations.php @@ -678,4 +678,7 @@ return array( // 'Disable login form' => '', // 'Show/hide calendar' => '', // 'User calendar' => '', + // 'Bitbucket commit received' => '', + // 'Bitbucket webhooks' => '', + // 'Help on Bitbucket webhooks' => '', ); diff --git a/app/Model/Action.php b/app/Model/Action.php index 6aef81a3e..6fb2a2f1e 100644 --- a/app/Model/Action.php +++ b/app/Model/Action.php @@ -4,6 +4,7 @@ namespace Model; use Integration\GitlabWebhook; use Integration\GithubWebhook; +use Integration\BitbucketWebhook; use SimpleValidator\Validator; use SimpleValidator\Validators; @@ -85,6 +86,7 @@ class Action extends Base GitlabWebhook::EVENT_COMMIT => t('Gitlab commit received'), GitlabWebhook::EVENT_ISSUE_OPENED => t('Gitlab issue opened'), GitlabWebhook::EVENT_ISSUE_CLOSED => t('Gitlab issue closed'), + BitbucketWebhook::EVENT_COMMIT => t('Bitbucket commit received'), ); asort($values); diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php index 48157991b..bee031842 100644 --- a/app/ServiceProvider/ClassProvider.php +++ b/app/ServiceProvider/ClassProvider.php @@ -62,6 +62,7 @@ class ClassProvider implements ServiceProviderInterface 'Integration' => array( 'GitlabWebhook', 'GithubWebhook', + 'BitbucketWebhook', ) ); diff --git a/app/Template/project/integrations.php b/app/Template/project/integrations.php index 8ec43f906..194bd672e 100644 --- a/app/Template/project/integrations.php +++ b/app/Template/project/integrations.php @@ -12,4 +12,10 @@
+ +