Add Bitbucket webhook
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
}
|
||||
|
||||
98
app/Integration/BitbucketWebhook.php
Normal file
98
app/Integration/BitbucketWebhook.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Integration;
|
||||
|
||||
use Event\GenericEvent;
|
||||
use Event\TaskEvent;
|
||||
use Model\Task;
|
||||
|
||||
/**
|
||||
* Bitbucket Webhook
|
||||
*
|
||||
* @package integration
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class BitbucketWebhook extends Base
|
||||
{
|
||||
/**
|
||||
* Events
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const EVENT_COMMIT = 'bitbucket.webhook.commit';
|
||||
|
||||
/**
|
||||
* Project id
|
||||
*
|
||||
* @access private
|
||||
* @var integer
|
||||
*/
|
||||
private $project_id = 0;
|
||||
|
||||
/**
|
||||
* Set the project id
|
||||
*
|
||||
* @access public
|
||||
* @param integer $project_id Project id
|
||||
*/
|
||||
public function setProjectId($project_id)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
@@ -678,4 +678,7 @@ return array(
|
||||
// 'Disable login form' => '',
|
||||
// 'Show/hide calendar' => '',
|
||||
// 'User calendar' => '',
|
||||
// 'Bitbucket commit received' => '',
|
||||
// 'Bitbucket webhooks' => '',
|
||||
// 'Help on Bitbucket webhooks' => '',
|
||||
);
|
||||
|
||||
@@ -678,4 +678,7 @@ return array(
|
||||
// 'Disable login form' => '',
|
||||
// 'Show/hide calendar' => '',
|
||||
// 'User calendar' => '',
|
||||
// 'Bitbucket commit received' => '',
|
||||
// 'Bitbucket webhooks' => '',
|
||||
// 'Help on Bitbucket webhooks' => '',
|
||||
);
|
||||
|
||||
@@ -678,4 +678,7 @@ return array(
|
||||
// 'Disable login form' => '',
|
||||
// 'Show/hide calendar' => '',
|
||||
// 'User calendar' => '',
|
||||
// 'Bitbucket commit received' => '',
|
||||
// 'Bitbucket webhooks' => '',
|
||||
// 'Help on Bitbucket webhooks' => '',
|
||||
);
|
||||
|
||||
@@ -678,4 +678,7 @@ return array(
|
||||
// 'Disable login form' => '',
|
||||
// 'Show/hide calendar' => '',
|
||||
// 'User calendar' => '',
|
||||
// 'Bitbucket commit received' => '',
|
||||
// 'Bitbucket webhooks' => '',
|
||||
// 'Help on Bitbucket webhooks' => '',
|
||||
);
|
||||
|
||||
@@ -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',
|
||||
);
|
||||
|
||||
@@ -678,4 +678,7 @@ return array(
|
||||
// 'Disable login form' => '',
|
||||
// 'Show/hide calendar' => '',
|
||||
// 'User calendar' => '',
|
||||
// 'Bitbucket commit received' => '',
|
||||
// 'Bitbucket webhooks' => '',
|
||||
// 'Help on Bitbucket webhooks' => '',
|
||||
);
|
||||
|
||||
@@ -678,4 +678,7 @@ return array(
|
||||
// 'Disable login form' => '',
|
||||
// 'Show/hide calendar' => '',
|
||||
// 'User calendar' => '',
|
||||
// 'Bitbucket commit received' => '',
|
||||
// 'Bitbucket webhooks' => '',
|
||||
// 'Help on Bitbucket webhooks' => '',
|
||||
);
|
||||
|
||||
@@ -678,4 +678,7 @@ return array(
|
||||
// 'Disable login form' => '',
|
||||
// 'Show/hide calendar' => '',
|
||||
// 'User calendar' => '',
|
||||
// 'Bitbucket commit received' => '',
|
||||
// 'Bitbucket webhooks' => '',
|
||||
// 'Help on Bitbucket webhooks' => '',
|
||||
);
|
||||
|
||||
@@ -678,4 +678,7 @@ return array(
|
||||
// 'Disable login form' => '',
|
||||
// 'Show/hide calendar' => '',
|
||||
// 'User calendar' => '',
|
||||
// 'Bitbucket commit received' => '',
|
||||
// 'Bitbucket webhooks' => '',
|
||||
// 'Help on Bitbucket webhooks' => '',
|
||||
);
|
||||
|
||||
@@ -678,4 +678,7 @@ return array(
|
||||
// 'Disable login form' => '',
|
||||
// 'Show/hide calendar' => '',
|
||||
// 'User calendar' => '',
|
||||
// 'Bitbucket commit received' => '',
|
||||
// 'Bitbucket webhooks' => '',
|
||||
// 'Help on Bitbucket webhooks' => '',
|
||||
);
|
||||
|
||||
@@ -678,4 +678,7 @@ return array(
|
||||
// 'Disable login form' => '',
|
||||
// 'Show/hide calendar' => '',
|
||||
// 'User calendar' => '',
|
||||
// 'Bitbucket commit received' => '',
|
||||
// 'Bitbucket webhooks' => '',
|
||||
// 'Help on Bitbucket webhooks' => '',
|
||||
);
|
||||
|
||||
@@ -678,4 +678,7 @@ return array(
|
||||
// 'Disable login form' => '',
|
||||
// 'Show/hide calendar' => '',
|
||||
// 'User calendar' => '',
|
||||
// 'Bitbucket commit received' => '',
|
||||
// 'Bitbucket webhooks' => '',
|
||||
// 'Help on Bitbucket webhooks' => '',
|
||||
);
|
||||
|
||||
@@ -678,4 +678,7 @@ return array(
|
||||
// 'Disable login form' => '',
|
||||
// 'Show/hide calendar' => '',
|
||||
// 'User calendar' => '',
|
||||
// 'Bitbucket commit received' => '',
|
||||
// 'Bitbucket webhooks' => '',
|
||||
// 'Help on Bitbucket webhooks' => '',
|
||||
);
|
||||
|
||||
@@ -678,4 +678,7 @@ return array(
|
||||
// 'Disable login form' => '',
|
||||
// 'Show/hide calendar' => '',
|
||||
// 'User calendar' => '',
|
||||
// 'Bitbucket commit received' => '',
|
||||
// 'Bitbucket webhooks' => '',
|
||||
// 'Help on Bitbucket webhooks' => '',
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -62,6 +62,7 @@ class ClassProvider implements ServiceProviderInterface
|
||||
'Integration' => array(
|
||||
'GitlabWebhook',
|
||||
'GithubWebhook',
|
||||
'BitbucketWebhook',
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -12,4 +12,10 @@
|
||||
<div class="listing">
|
||||
<input type="text" class="auto-select" readonly="readonly" value="<?= $this->getCurrentBaseUrl().$this->u('webhook', 'gitlab', array('token' => $webhook_token, 'project_id' => $project['id'])) ?>"/><br/>
|
||||
<p class="form-help"><a href="http://kanboard.net/documentation/gitlab-webhooks" target="_blank"><?= t('Help on Gitlab webhooks') ?></a></p>
|
||||
</div>
|
||||
|
||||
<h3><i class="fa fa-bitbucket fa-fw"></i> <?= t('Bitbucket webhooks') ?></h3>
|
||||
<div class="listing">
|
||||
<input type="text" class="auto-select" readonly="readonly" value="<?= $this->getCurrentBaseUrl().$this->u('webhook', 'bitbucket', array('token' => $webhook_token, 'project_id' => $project['id'])) ?>"/><br/>
|
||||
<p class="form-help"><a href="http://kanboard.net/documentation/bitbucket-webhooks" target="_blank"><?= t('Help on Bitbucket webhooks') ?></a></p>
|
||||
</div>
|
||||
Reference in New Issue
Block a user