summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-06-21 12:19:06 -0400
committerFrederic Guillot <fred@kanboard.net>2015-06-21 12:19:06 -0400
commitd7a8160c2b422dcf950093d9d17d90f1e80201de (patch)
tree51ad4b6bd086e178406ec2b6c5b29699f7917cf7
parent98fd34bfe340fae6d0fd3b7333b6f9a6647cbae2 (diff)
Update Bitbucket webhooks to handle issues/commit/comments
-rw-r--r--app/Action/ActionCommentCreationTest.php124
-rw-r--r--app/Action/CommentCreation.php1
-rw-r--r--app/Action/TaskAssignUser.php2
-rw-r--r--app/Action/TaskClose.php4
-rw-r--r--app/Action/TaskCreation.php2
-rw-r--r--app/Action/TaskOpen.php2
-rw-r--r--app/Controller/Webhook.php12
-rw-r--r--app/Core/Request.php2
-rw-r--r--app/Integration/BitbucketWebhook.php236
-rw-r--r--app/Model/Action.php7
-rw-r--r--docs/automatic-actions.markdown16
-rw-r--r--docs/bitbucket-webhooks.markdown21
-rw-r--r--tests/units/ActionCommentCreationTest.php83
-rw-r--r--tests/units/BitbucketWebhookTest.php376
-rw-r--r--tests/units/GithubWebhookTest.php1
-rw-r--r--tests/units/fixtures/bitbucket_comment_created.json147
-rw-r--r--tests/units/fixtures/bitbucket_issue_assigned.json209
-rw-r--r--tests/units/fixtures/bitbucket_issue_closed.json183
-rw-r--r--tests/units/fixtures/bitbucket_issue_opened.json112
-rw-r--r--tests/units/fixtures/bitbucket_issue_reopened.json183
-rw-r--r--tests/units/fixtures/bitbucket_issue_unassigned.json193
-rw-r--r--tests/units/fixtures/bitbucket_push.json182
22 files changed, 1924 insertions, 174 deletions
diff --git a/app/Action/ActionCommentCreationTest.php b/app/Action/ActionCommentCreationTest.php
deleted file mode 100644
index a4ca284e..00000000
--- a/app/Action/ActionCommentCreationTest.php
+++ /dev/null
@@ -1,124 +0,0 @@
-<?php
-
-require_once __DIR__.'/Base.php';
-
-use Event\GenericEvent;
-use Model\Task;
-use Model\TaskCreation;
-use Model\Comment;
-use Model\Project;
-use Integration\GithubWebhook;
-
-class ActionCommentCreationTest extends Base
-{
- public function testWithoutRequiredParams()
- {
- $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
-
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $p = new Project($this->container);
- $c = new Comment($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
-
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'user_id' => 1,
- );
-
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
-
- $comment = $c->getById(1);
- $this->assertEmpty($comment);
- }
-
- public function testWithCommitMessage()
- {
- $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
-
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $p = new Project($this->container);
- $c = new Comment($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
-
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'commit_comment' => 'plop',
- );
-
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
-
- $comment = $c->getById(1);
- $this->assertNotEmpty($comment);
- $this->assertEquals(1, $comment['task_id']);
- $this->assertEquals(0, $comment['user_id']);
- $this->assertEquals('plop', $comment['comment']);
- }
-
- public function testWithUser()
- {
- $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
-
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $p = new Project($this->container);
- $c = new Comment($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
-
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'user_id' => 1,
- 'comment' => 'youpi',
- );
-
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
-
- $comment = $c->getById(1);
- $this->assertNotEmpty($comment);
- $this->assertEquals(1, $comment['task_id']);
- $this->assertEquals(1, $comment['user_id']);
- $this->assertEquals('youpi', $comment['comment']);
- }
-
- public function testWithNoUser()
- {
- $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
-
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $p = new Project($this->container);
- $c = new Comment($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
-
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'user_id' => 0,
- 'comment' => 'youpi',
- );
-
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
-
- $comment = $c->getById(1);
- $this->assertNotEmpty($comment);
- $this->assertEquals(1, $comment['task_id']);
- $this->assertEquals(0, $comment['user_id']);
- $this->assertEquals('youpi', $comment['comment']);
- }
-}
diff --git a/app/Action/CommentCreation.php b/app/Action/CommentCreation.php
index fb9f1172..5dfd1c89 100644
--- a/app/Action/CommentCreation.php
+++ b/app/Action/CommentCreation.php
@@ -25,6 +25,7 @@ class CommentCreation extends Base
return array(
GithubWebhook::EVENT_ISSUE_COMMENT,
GithubWebhook::EVENT_COMMIT,
+ BitbucketWebhook::EVENT_ISSUE_COMMENT,
BitbucketWebhook::EVENT_COMMIT,
GitlabWebhook::EVENT_COMMIT,
);
diff --git a/app/Action/TaskAssignUser.php b/app/Action/TaskAssignUser.php
index cf2a9a4b..c28df9fb 100644
--- a/app/Action/TaskAssignUser.php
+++ b/app/Action/TaskAssignUser.php
@@ -3,6 +3,7 @@
namespace Action;
use Integration\GithubWebhook;
+use Integration\BitbucketWebhook;
/**
* Assign a task to someone
@@ -22,6 +23,7 @@ class TaskAssignUser extends Base
{
return array(
GithubWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE,
+ BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE,
);
}
diff --git a/app/Action/TaskClose.php b/app/Action/TaskClose.php
index b7cd4dbf..0fe58dac 100644
--- a/app/Action/TaskClose.php
+++ b/app/Action/TaskClose.php
@@ -30,6 +30,7 @@ class TaskClose extends Base
GitlabWebhook::EVENT_COMMIT,
GitlabWebhook::EVENT_ISSUE_CLOSED,
BitbucketWebhook::EVENT_COMMIT,
+ BitbucketWebhook::EVENT_ISSUE_CLOSED,
);
}
@@ -47,6 +48,7 @@ class TaskClose extends Base
case GitlabWebhook::EVENT_COMMIT:
case GitlabWebhook::EVENT_ISSUE_CLOSED:
case BitbucketWebhook::EVENT_COMMIT:
+ case BitbucketWebhook::EVENT_ISSUE_CLOSED:
return array();
default:
return array('column_id' => t('Column'));
@@ -67,6 +69,7 @@ class TaskClose extends Base
case GitlabWebhook::EVENT_COMMIT:
case GitlabWebhook::EVENT_ISSUE_CLOSED:
case BitbucketWebhook::EVENT_COMMIT:
+ case BitbucketWebhook::EVENT_ISSUE_CLOSED:
return array('task_id');
default:
return array('task_id', 'column_id');
@@ -100,6 +103,7 @@ class TaskClose extends Base
case GitlabWebhook::EVENT_COMMIT:
case GitlabWebhook::EVENT_ISSUE_CLOSED:
case BitbucketWebhook::EVENT_COMMIT:
+ case BitbucketWebhook::EVENT_ISSUE_CLOSED:
return true;
default:
return $data['column_id'] == $this->getParam('column_id');
diff --git a/app/Action/TaskCreation.php b/app/Action/TaskCreation.php
index 1c093eee..bb5b05c2 100644
--- a/app/Action/TaskCreation.php
+++ b/app/Action/TaskCreation.php
@@ -4,6 +4,7 @@ namespace Action;
use Integration\GithubWebhook;
use Integration\GitlabWebhook;
+use Integration\BitbucketWebhook;
/**
* Create automatically a task from a webhook
@@ -24,6 +25,7 @@ class TaskCreation extends Base
return array(
GithubWebhook::EVENT_ISSUE_OPENED,
GitlabWebhook::EVENT_ISSUE_OPENED,
+ BitbucketWebhook::EVENT_ISSUE_OPENED,
);
}
diff --git a/app/Action/TaskOpen.php b/app/Action/TaskOpen.php
index 73f1fad3..ee42ab32 100644
--- a/app/Action/TaskOpen.php
+++ b/app/Action/TaskOpen.php
@@ -3,6 +3,7 @@
namespace Action;
use Integration\GithubWebhook;
+use Integration\BitbucketWebhook;
/**
* Open automatically a task
@@ -22,6 +23,7 @@ class TaskOpen extends Base
{
return array(
GithubWebhook::EVENT_ISSUE_REOPENED,
+ BitbucketWebhook::EVENT_ISSUE_REOPENED,
);
}
diff --git a/app/Controller/Webhook.php b/app/Controller/Webhook.php
index d04f83b3..1a4cfe9a 100644
--- a/app/Controller/Webhook.php
+++ b/app/Controller/Webhook.php
@@ -53,7 +53,7 @@ class Webhook extends Base
$result = $this->githubWebhook->parsePayload(
$this->request->getHeader('X-Github-Event'),
- $this->request->getJson() ?: array()
+ $this->request->getJson()
);
echo $result ? 'PARSED' : 'IGNORED';
@@ -69,7 +69,7 @@ class Webhook extends Base
$this->checkWebhookToken();
$this->gitlabWebhook->setProjectId($this->request->getIntegerParam('project_id'));
- $result = $this->gitlabWebhook->parsePayload($this->request->getJson() ?: array());
+ $result = $this->gitlabWebhook->parsePayload($this->request->getJson());
echo $result ? 'PARSED' : 'IGNORED';
}
@@ -84,7 +84,11 @@ class Webhook extends Base
$this->checkWebhookToken();
$this->bitbucketWebhook->setProjectId($this->request->getIntegerParam('project_id'));
- $result = $this->bitbucketWebhook->parsePayload(json_decode(@$_POST['payload'], true) ?: array());
+
+ $result = $this->bitbucketWebhook->parsePayload(
+ $this->request->getHeader('X-Event-Key'),
+ $this->request->getJson()
+ );
echo $result ? 'PARSED' : 'IGNORED';
}
@@ -97,7 +101,7 @@ class Webhook extends Base
public function postmark()
{
$this->checkWebhookToken();
- echo $this->postmark->receiveEmail($this->request->getJson() ?: array()) ? 'PARSED' : 'IGNORED';
+ echo $this->postmark->receiveEmail($this->request->getJson()) ? 'PARSED' : 'IGNORED';
}
/**
diff --git a/app/Core/Request.php b/app/Core/Request.php
index c7ca3184..b399a1f0 100644
--- a/app/Core/Request.php
+++ b/app/Core/Request.php
@@ -83,7 +83,7 @@ class Request
*/
public function getJson()
{
- return json_decode($this->getBody(), true);
+ return json_decode($this->getBody(), true) ?: array();
}
/**
diff --git a/app/Integration/BitbucketWebhook.php b/app/Integration/BitbucketWebhook.php
index eced5596..d9dc45b1 100644
--- a/app/Integration/BitbucketWebhook.php
+++ b/app/Integration/BitbucketWebhook.php
@@ -18,7 +18,12 @@ class BitbucketWebhook extends \Core\Base
*
* @var string
*/
- const EVENT_COMMIT = 'bitbucket.webhook.commit';
+ const EVENT_COMMIT = 'bitbucket.webhook.commit';
+ const EVENT_ISSUE_OPENED = 'bitbucket.webhook.issue.opened';
+ const EVENT_ISSUE_CLOSED = 'bitbucket.webhook.issue.closed';
+ const EVENT_ISSUE_REOPENED = 'bitbucket.webhook.issue.reopened';
+ const EVENT_ISSUE_ASSIGNEE_CHANGE = 'bitbucket.webhook.issue.assignee';
+ const EVENT_ISSUE_COMMENT = 'bitbucket.webhook.issue.commented';
/**
* Project id
@@ -40,19 +45,227 @@ class BitbucketWebhook extends \Core\Base
}
/**
- * Parse events
+ * Parse incoming events
*
* @access public
- * @param array $payload Gitlab event
+ * @param string $type Bitbucket event type
+ * @param array $payload Bitbucket event
* @return boolean
*/
- public function parsePayload(array $payload)
+ public function parsePayload($type, array $payload)
{
- if (! empty($payload['commits'])) {
+ switch ($type) {
+ case 'issue:comment_created':
+ return $this->handleCommentCreated($payload);
+ case 'issue:created':
+ return $this->handleIssueOpened($payload);
+ case 'issue:updated':
+ return $this->handleIssueUpdated($payload);
+ case 'repo:push':
+ return $this->handlePush($payload);
+ }
+
+ return false;
+ }
+
+ /**
+ * Parse comment issue events
+ *
+ * @access public
+ * @param array $payload
+ * @return boolean
+ */
+ public function handleCommentCreated(array $payload)
+ {
+ $task = $this->taskFinder->getByReference($this->project_id, $payload['issue']['id']);
+
+ if (! empty($task)) {
+
+ $user = $this->user->getByUsername($payload['actor']['username']);
+
+ if (! empty($user) && ! $this->projectPermission->isMember($this->project_id, $user['id'])) {
+ $user = array();
+ }
+
+ $event = array(
+ 'project_id' => $this->project_id,
+ 'reference' => $payload['comment']['id'],
+ 'comment' => $payload['comment']['content']['raw']."\n\n[".t('By @%s on Bitbucket', $payload['actor']['display_name']).']('.$payload['comment']['links']['html']['href'].')',
+ 'user_id' => ! empty($user) ? $user['id'] : 0,
+ 'task_id' => $task['id'],
+ );
+
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_ISSUE_COMMENT,
+ new GenericEvent($event)
+ );
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Handle new issues
+ *
+ * @access public
+ * @param array $payload
+ * @return boolean
+ */
+ public function handleIssueOpened(array $payload)
+ {
+ $event = array(
+ 'project_id' => $this->project_id,
+ 'reference' => $payload['issue']['id'],
+ 'title' => $payload['issue']['title'],
+ 'description' => $payload['issue']['content']['raw']."\n\n[".t('Bitbucket Issue').']('.$payload['issue']['links']['html']['href'].')',
+ );
+
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_ISSUE_OPENED,
+ new GenericEvent($event)
+ );
+
+ return true;
+ }
+
+ /**
+ * Handle issue updates
+ *
+ * @access public
+ * @param array $payload
+ * @return boolean
+ */
+ public function handleIssueUpdated(array $payload)
+ {
+ $task = $this->taskFinder->getByReference($this->project_id, $payload['issue']['id']);
+
+ if (empty($task)) {
+ return false;
+ }
+
+ if (isset($payload['changes']['status'])) {
+ return $this->handleStatusChange($task, $payload);
+ }
+ else if (isset($payload['changes']['assignee'])) {
+ return $this->handleAssigneeChange($task, $payload);
+ }
+
+ return false;
+ }
+
+ /**
+ * Handle issue status change
+ *
+ * @access public
+ * @param array $task
+ * @param array $payload
+ * @return boolean
+ */
+ public function handleStatusChange(array $task, array $payload)
+ {
+ $event = array(
+ 'project_id' => $this->project_id,
+ 'task_id' => $task['id'],
+ 'reference' => $payload['issue']['id'],
+ );
+
+ switch ($payload['issue']['state']) {
+ case 'closed':
+ $this->container['dispatcher']->dispatch(self::EVENT_ISSUE_CLOSED, new GenericEvent($event));
+ return true;
+ case 'open':
+ $this->container['dispatcher']->dispatch(self::EVENT_ISSUE_REOPENED, new GenericEvent($event));
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Handle issue assignee change
+ *
+ * @access public
+ * @param array $task
+ * @param array $payload
+ * @return boolean
+ */
+ public function handleAssigneeChange(array $task, array $payload)
+ {
+ if (empty($payload['issue']['assignee'])) {
+ return $this->handleIssueUnassigned($task, $payload);
+ }
+
+ return $this->handleIssueAssigned($task, $payload);
+ }
+
+ /**
+ * Handle issue assigned
+ *
+ * @access public
+ * @param array $task
+ * @param array $payload
+ * @return boolean
+ */
+ public function handleIssueAssigned(array $task, array $payload)
+ {
+ $user = $this->user->getByUsername($payload['issue']['assignee']['username']);
+
+ if (empty($user)) {
+ return false;
+ }
+
+ if (! $this->projectPermission->isMember($this->project_id, $user['id'])) {
+ return false;
+ }
+
+ $event = array(
+ 'project_id' => $this->project_id,
+ 'task_id' => $task['id'],
+ 'owner_id' => $user['id'],
+ 'reference' => $payload['issue']['id'],
+ );
+
+ $this->container['dispatcher']->dispatch(self::EVENT_ISSUE_ASSIGNEE_CHANGE, new GenericEvent($event));
+
+ return true;
+ }
+
+ /**
+ * Handle issue unassigned
+ *
+ * @access public
+ * @param array $task
+ * @param array $payload
+ * @return boolean
+ */
+ public function handleIssueUnassigned(array $task, array $payload)
+ {
+ $event = array(
+ 'project_id' => $this->project_id,
+ 'task_id' => $task['id'],
+ 'owner_id' => 0,
+ 'reference' => $payload['issue']['id'],
+ );
+
+ $this->container['dispatcher']->dispatch(self::EVENT_ISSUE_ASSIGNEE_CHANGE, new GenericEvent($event));
- foreach ($payload['commits'] as $commit) {
+ return true;
+ }
- if ($this->handleCommit($commit)) {
+ /**
+ * Parse push events
+ *
+ * @access public
+ * @param array $payload
+ * @return boolean
+ */
+ public function handlePush(array $payload)
+ {
+ if (isset($payload['push']['changes'])) {
+ foreach ($payload['push']['changes'] as $change) {
+ if (isset($change['new']['target']) && $this->handleCommit($change['new']['target'], $payload['actor'])) {
return true;
}
}
@@ -65,10 +278,11 @@ class BitbucketWebhook extends \Core\Base
* Parse commit
*
* @access public
- * @param array $commit Gitlab commit
+ * @param array $commit Bitbucket commit
+ * @param array $actor Bitbucket actor
* @return boolean
*/
- public function handleCommit(array $commit)
+ public function handleCommit(array $commit, array $actor)
{
$task_id = $this->task->getTaskIdFromText($commit['message']);
@@ -91,8 +305,8 @@ class BitbucketWebhook extends \Core\Base
new GenericEvent(array(
'task_id' => $task_id,
'commit_message' => $commit['message'],
- 'commit_url' => '',
- 'commit_comment' => $commit['message']."\n\n".t('Commit made by @%s on Bitbucket', $commit['author'])
+ 'commit_url' => $commit['links']['html']['href'],
+ 'commit_comment' => $commit['message']."\n\n[".t('Commit made by @%s on Bitbucket', $actor['display_name']).']('.$commit['links']['html']['href'].')',
) + $task)
);
diff --git a/app/Model/Action.php b/app/Model/Action.php
index 35872bdd..4ede5661 100644
--- a/app/Model/Action.php
+++ b/app/Model/Action.php
@@ -78,7 +78,7 @@ class Action extends Base
Task::EVENT_MOVE_COLUMN => t('Move a task to another column'),
Task::EVENT_UPDATE => t('Task modification'),
Task::EVENT_CREATE => t('Task creation'),
- Task::EVENT_OPEN => t('Open a closed task'),
+ Task::EVENT_OPEN => t('Reopen a task'),
Task::EVENT_CLOSE => t('Closing a task'),
Task::EVENT_CREATE_UPDATE => t('Task creation or modification'),
Task::EVENT_ASSIGNEE_CHANGE => t('Task assignee change'),
@@ -93,6 +93,11 @@ class Action extends Base
GitlabWebhook::EVENT_ISSUE_OPENED => t('Gitlab issue opened'),
GitlabWebhook::EVENT_ISSUE_CLOSED => t('Gitlab issue closed'),
BitbucketWebhook::EVENT_COMMIT => t('Bitbucket commit received'),
+ BitbucketWebhook::EVENT_ISSUE_OPENED => t('Bitbucket issue opened'),
+ BitbucketWebhook::EVENT_ISSUE_CLOSED => t('Bitbucket issue closed'),
+ BitbucketWebhook::EVENT_ISSUE_REOPENED => t('Bitbucket issue reopened'),
+ BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE => t('Bitbucket issue assignee change'),
+ BitbucketWebhook::EVENT_ISSUE_COMMENT => t('Bitbucket issue comment created'),
);
asort($values);
diff --git a/docs/automatic-actions.markdown b/docs/automatic-actions.markdown
index b812f9cc..6fb0005d 100644
--- a/docs/automatic-actions.markdown
+++ b/docs/automatic-actions.markdown
@@ -33,7 +33,7 @@ List of available events
- Move a task to another position in the same column
- Task modification
- Task creation
-- Open a closed task
+- Reopen a task
- Closing a task
- Task creation or modification
- Task assignee change
@@ -47,23 +47,35 @@ List of available events
- Gitlab issue opened
- Gitlab issue closed
- Gitlab commit received
+- Bitbucket commit received
+- Bitbucket issue opened
+- Bitbucket issue closed
+- Bitbucket issue reopened
+- Bitbucket issue assignee change
+- Bitbucket issue comment created
List of available actions
-------------------------
- Close the task
+- Open a task
- Assign the task to a specific user
- Assign the task to the person who does the action
- Duplicate the task to another project
- Move the task to another project
+- Move the task to another column when assigned to a user
+- Move the task to another column when assignee is cleared
+- Assign a color when the task is moved to a specific column
- Assign a color to a specific user
- Assign automatically a color based on a category
- Assign automatically a category based on a color
+- Create a comment from an external provider
- Create a task from an external provider
+- Add a comment log when moving the task between columns
- Change the assignee based on an external username
- Change the category based on an external label
-- Create a comment from an external provider
- Automatically update the start date
+- Move the task to another column when the category is changed
- Send a task by email to someone
Examples
diff --git a/docs/bitbucket-webhooks.markdown b/docs/bitbucket-webhooks.markdown
index fbb80d12..7f59aa11 100644
--- a/docs/bitbucket-webhooks.markdown
+++ b/docs/bitbucket-webhooks.markdown
@@ -7,11 +7,20 @@ List of supported events
------------------------
- Bitbucket commit received
+- Bitbucket issue opened
+- Bitbucket issue closed
+- Bitbucket issue reopened
+- Bitbucket issue assignee change
+- Bitbucket issue comment created
List of supported actions
-------------------------
+- Create a task from an external provider
+- Change the assignee based on an external username
+- Create a comment from an external provider
- Close a task
+- Open a task
Configuration
-------------
@@ -20,9 +29,8 @@ Configuration
1. On Kanboard, go to the project settings and choose the section **Integrations**
2. Copy the Bitbucket webhook url
-3. On Bitbucket, go to the project settings and go to the section **Hooks**
-4. Select the service **POST**
-5. Paste the url and save
+3. On Bitbucket, go to the project settings and go to the section **Webhooks**
+4. Choose a title for your webhook and paste the Kanboard url
Examples
--------
@@ -38,3 +46,10 @@ Example:
- Commit message: "Fix bug #1234"
- That will close the Kanboard task #1234
+
+### Add comment when a commit received
+
+- Choose the event: **Bitbucket commit received**
+- Choose the action: **Create a comment from an external provider**
+
+The comment will contains the commit message and the url to the commit.
diff --git a/tests/units/ActionCommentCreationTest.php b/tests/units/ActionCommentCreationTest.php
index 03f45f28..cf9e1e0a 100644
--- a/tests/units/ActionCommentCreationTest.php
+++ b/tests/units/ActionCommentCreationTest.php
@@ -11,6 +11,59 @@ use Integration\GithubWebhook;
class ActionCommentCreationTest extends Base
{
+ public function testWithoutRequiredParams()
+ {
+ $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
+
+ // We create a task in the first column
+ $tc = new TaskCreation($this->container);
+ $p = new Project($this->container);
+ $c = new Comment($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+
+ // We create an event to move the task to the 2nd column
+ $event = array(
+ 'project_id' => 1,
+ 'task_id' => 1,
+ 'user_id' => 1,
+ );
+
+ // Our event should be executed
+ $this->assertFalse($action->execute(new GenericEvent($event)));
+
+ $comment = $c->getById(1);
+ $this->assertEmpty($comment);
+ }
+
+ public function testWithCommitMessage()
+ {
+ $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
+
+ // We create a task in the first column
+ $tc = new TaskCreation($this->container);
+ $p = new Project($this->container);
+ $c = new Comment($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+
+ // We create an event to move the task to the 2nd column
+ $event = array(
+ 'project_id' => 1,
+ 'task_id' => 1,
+ 'commit_comment' => 'plop',
+ );
+
+ // Our event should be executed
+ $this->assertTrue($action->execute(new GenericEvent($event)));
+
+ $comment = $c->getById(1);
+ $this->assertNotEmpty($comment);
+ $this->assertEquals(1, $comment['task_id']);
+ $this->assertEquals(0, $comment['user_id']);
+ $this->assertEquals('plop', $comment['comment']);
+ }
+
public function testWithUser()
{
$action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
@@ -33,11 +86,39 @@ class ActionCommentCreationTest extends Base
// Our event should be executed
$this->assertTrue($action->execute(new GenericEvent($event)));
- // Our task should be updated
$comment = $c->getById(1);
$this->assertNotEmpty($comment);
$this->assertEquals(1, $comment['task_id']);
$this->assertEquals(1, $comment['user_id']);
$this->assertEquals('youpi', $comment['comment']);
}
+
+ public function testWithNoUser()
+ {
+ $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
+
+ // We create a task in the first column
+ $tc = new TaskCreation($this->container);
+ $p = new Project($this->container);
+ $c = new Comment($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+
+ // We create an event to move the task to the 2nd column
+ $event = array(
+ 'project_id' => 1,
+ 'task_id' => 1,
+ 'user_id' => 0,
+ 'comment' => 'youpi',
+ );
+
+ // Our event should be executed
+ $this->assertTrue($action->execute(new GenericEvent($event)));
+
+ $comment = $c->getById(1);
+ $this->assertNotEmpty($comment);
+ $this->assertEquals(1, $comment['task_id']);
+ $this->assertEquals(0, $comment['user_id']);
+ $this->assertEquals('youpi', $comment['comment']);
+ }
}
diff --git a/tests/units/BitbucketWebhookTest.php b/tests/units/BitbucketWebhookTest.php
index f1735d3d..afc8be1d 100644
--- a/tests/units/BitbucketWebhookTest.php
+++ b/tests/units/BitbucketWebhookTest.php
@@ -6,61 +6,310 @@ use Integration\BitbucketWebhook;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
+use Model\ProjectPermission;
+use Model\User;
class BitbucketWebhookTest extends Base
{
- private $post_payload = '{"repository": {"website": "", "fork": false, "name": "webhooks", "scm": "git", "owner": "minicoders", "absolute_url": "/minicoders/webhooks/", "slug": "webhooks", "is_private": true}, "truncated": false, "commits": [{"node": "28569937627f", "files": [{"type": "added", "file": "README.md"}], "raw_author": "Frederic Guillot <fred@localhost>", "utctimestamp": "2015-02-09 00:57:45+00:00", "author": "Frederic Guillot", "timestamp": "2015-02-09 01:57:45", "raw_node": "28569937627fb406eeda9376a02b39581a974d4f", "parents": [], "branch": "master", "message": "first commit\\n", "revision": null, "size": -1}, {"node": "285699376274", "files": [{"type": "added", "file": "README.md"}], "raw_author": "Frederic Guillot <fred@localhost>", "utctimestamp": "2015-02-09 00:57:45+00:00", "author": "Frederic Guillot", "timestamp": "2015-02-09 01:57:45", "raw_node": "28569937627fb406eeda9376a02b39581a974d4f", "parents": [], "branch": "master", "message": "Fix #2\\n", "revision": null, "size": -1}], "canon_url": "https://bitbucket.org", "user": "minicoders"}';
-
- public function testHandleCommit()
+ public function testHandlePush()
{
- $g = new BitbucketWebhook($this->container);
- $p = new Project($this->container);
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_COMMIT, array($this, 'onCommit'));
+
$tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $bw = new BitbucketWebhook($this->container);
+ $payload = json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_push.json'), true);
$this->assertEquals(1, $p->create(array('name' => 'test')));
- $g->setProjectId(1);
-
- $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_COMMIT, array($this, 'onCommit'));
-
- $event = json_decode($this->post_payload, true);
+ $bw->setProjectId(1);
// No task
- $this->assertFalse($g->handleCommit($event['commits'][0]));
+ $this->assertFalse($bw->handlePush($payload));
// Create task with the wrong id
$this->assertEquals(1, $tc->create(array('title' => 'test1', 'project_id' => 1)));
- $this->assertFalse($g->handleCommit($event['commits'][1]));
+ $this->assertFalse($bw->handlePush($payload));
// Create task with the right id
$this->assertEquals(2, $tc->create(array('title' => 'test2', 'project_id' => 1)));
- $this->assertTrue($g->handleCommit($event['commits'][1]));
+ $this->assertTrue($bw->handlePush($payload));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(BitbucketWebhook::EVENT_COMMIT.'.BitbucketWebhookTest::onCommit', $called);
}
- public function testParsePayload()
+ public function testIssueOpened()
+ {
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_OPENED, array($this, 'onIssueOpened'));
+
+ $p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'foobar')));
+
+ $bw = new BitbucketWebhook($this->container);
+ $bw->setProjectId(1);
+
+ $this->assertNotFalse($bw->parsePayload(
+ 'issue:created',
+ json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_opened.json'), true)
+ ));
+ }
+
+ public function testCommentCreatedWithNoUser()
+ {
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNoUser'));
+
+ $p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'foobar')));
+
+ $tc = new TaskCreation($this->container);
+ $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1)));
+
+ $g = new BitbucketWebhook($this->container);
+ $g->setProjectId(1);
+
+ $this->assertNotFalse($g->parsePayload(
+ 'issue:comment_created',
+ json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_comment_created.json'), true)
+ ));
+ }
+
+ public function testCommentCreatedWithNotMember()
{
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNotMember'));
+
+ $p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'foobar')));
+
+ $tc = new TaskCreation($this->container);
+ $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1)));
+
+ $u = new User($this->container);
+ $this->assertEquals(2, $u->create(array('username' => 'fguillot')));
+
$g = new BitbucketWebhook($this->container);
+ $g->setProjectId(1);
+
+ $this->assertNotFalse($g->parsePayload(
+ 'issue:comment_created',
+ json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_comment_created.json'), true)
+ ));
+ }
+
+ public function testCommentCreatedWithUser()
+ {
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithUser'));
+
$p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'foobar')));
+
$tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
+ $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1)));
- $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_COMMIT, function() {});
+ $u = new User($this->container);
+ $this->assertEquals(2, $u->create(array('username' => 'minicoders')));
- $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $pp = new ProjectPermission($this->container);
+ $this->assertTrue($pp->addMember(1, 2));
+ $g = new BitbucketWebhook($this->container);
$g->setProjectId(1);
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertNotFalse($g->parsePayload(
+ 'issue:comment_created',
+ json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_comment_created.json'), true)
+ ));
+ }
+
+ public function testIssueClosed()
+ {
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_CLOSED, array($this, 'onIssueClosed'));
- $event = json_decode($this->post_payload, true);
- $this->assertTrue($g->parsePayload($event));
+ $p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'foobar')));
- $called = $this->container['dispatcher']->getCalledListeners();
- $this->assertArrayHasKey(BitbucketWebhook::EVENT_COMMIT.'.closure', $called);
+ $tc = new TaskCreation($this->container);
+ $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1)));
+
+ $g = new BitbucketWebhook($this->container);
+ $g->setProjectId(1);
+
+ $this->assertNotFalse($g->parsePayload(
+ 'issue:updated',
+ json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_closed.json'), true)
+ ));
+ }
+
+ public function testIssueClosedWithNoTask()
+ {
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_CLOSED, array($this, 'onIssueClosed'));
+
+ $p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'foobar')));
+
+ $tc = new TaskCreation($this->container);
+ $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 42, 'project_id' => 1)));
+
+ $g = new BitbucketWebhook($this->container);
+ $g->setProjectId(1);
+
+ $this->assertFalse($g->parsePayload(
+ 'issue:updated',
+ json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_closed.json'), true)
+ ));
+
+ $this->assertEmpty($this->container['dispatcher']->getCalledListeners());
+ }
+
+ public function testIssueReopened()
+ {
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_REOPENED, array($this, 'onIssueReopened'));
+
+ $p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'foobar')));
+
+ $tc = new TaskCreation($this->container);
+ $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1)));
+
+ $g = new BitbucketWebhook($this->container);
+ $g->setProjectId(1);
+
+ $this->assertNotFalse($g->parsePayload(
+ 'issue:updated',
+ json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_reopened.json'), true)
+ ));
+ }
+
+ public function testIssueReopenedWithNoTask()
+ {
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_REOPENED, array($this, 'onIssueReopened'));
+
+ $p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'foobar')));
+
+ $tc = new TaskCreation($this->container);
+ $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 42, 'project_id' => 1)));
+
+ $g = new BitbucketWebhook($this->container);
+ $g->setProjectId(1);
+
+ $this->assertFalse($g->parsePayload(
+ 'issue:updated',
+ json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_reopened.json'), true)
+ ));
+
+ $this->assertEmpty($this->container['dispatcher']->getCalledListeners());
+ }
+
+ public function testIssueUnassigned()
+ {
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueUnassigned'));
+
+ $p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'foobar')));
+
+ $tc = new TaskCreation($this->container);
+ $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1)));
+
+ $g = new BitbucketWebhook($this->container);
+ $g->setProjectId(1);
+
+ $this->assertNotFalse($g->parsePayload(
+ 'issue:updated',
+ json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_unassigned.json'), true)
+ ));
+ }
+
+ public function testIssueAssigned()
+ {
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueAssigned'));
+
+ $p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'foobar')));
+
+ $tc = new TaskCreation($this->container);
+ $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1)));
+
+ $u = new User($this->container);
+ $this->assertEquals(2, $u->create(array('username' => 'minicoders')));
+
+ $pp = new ProjectPermission($this->container);
+ $this->assertTrue($pp->addMember(1, 2));
+
+ $g = new BitbucketWebhook($this->container);
+ $g->setProjectId(1);
+
+ $this->assertNotFalse($g->parsePayload(
+ 'issue:updated',
+ json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_assigned.json'), true)
+ ));
+
+ $this->assertNotEmpty($this->container['dispatcher']->getCalledListeners());
+ }
+
+ public function testIssueAssignedWithNoPermission()
+ {
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, function() {});
+
+ $p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'foobar')));
+
+ $tc = new TaskCreation($this->container);
+ $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1)));
+
+ $u = new User($this->container);
+ $this->assertEquals(2, $u->create(array('username' => 'minicoders')));
+
+ $g = new BitbucketWebhook($this->container);
+ $g->setProjectId(1);
+
+ $this->assertFalse($g->parsePayload(
+ 'issue:updated',
+ json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_assigned.json'), true)
+ ));
+
+ $this->assertEmpty($this->container['dispatcher']->getCalledListeners());
+ }
+
+ public function testIssueAssignedWithNoUser()
+ {
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, function() {});
+
+ $p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'foobar')));
+
+ $tc = new TaskCreation($this->container);
+ $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1)));
+
+ $g = new BitbucketWebhook($this->container);
+ $g->setProjectId(1);
+
+ $this->assertFalse($g->parsePayload(
+ 'issue:updated',
+ json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_assigned.json'), true)
+ ));
+
+ $this->assertEmpty($this->container['dispatcher']->getCalledListeners());
+ }
+
+ public function testIssueAssignedWithNoTask()
+ {
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, function() {});
+
+ $p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'foobar')));
+
+ $tc = new TaskCreation($this->container);
+ $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 43, 'project_id' => 1)));
+
+ $g = new BitbucketWebhook($this->container);
+ $g->setProjectId(1);
+
+ $this->assertFalse($g->parsePayload(
+ 'issue:updated',
+ json_decode(file_get_contents(__DIR__.'/fixtures/bitbucket_issue_assigned.json'), true)
+ ));
+
+ $this->assertEmpty($this->container['dispatcher']->getCalledListeners());
}
public function onCommit($event)
@@ -69,8 +318,81 @@ class BitbucketWebhookTest extends Base
$this->assertEquals(1, $data['project_id']);
$this->assertEquals(2, $data['task_id']);
$this->assertEquals('test2', $data['title']);
- $this->assertEquals("Fix #2\n\n\nCommit made by @Frederic Guillot on Bitbucket", $data['commit_comment']);
- $this->assertEquals("Fix #2\n", $data['commit_message']);
- $this->assertEquals('', $data['commit_url']);
+ $this->assertEquals("Test another commit #2\n\n\n[Commit made by @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6)", $data['commit_comment']);
+ $this->assertEquals("Test another commit #2\n", $data['commit_message']);
+ $this->assertEquals('https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6', $data['commit_url']);
+ }
+
+ public function onIssueOpened($event)
+ {
+ $data = $event->getAll();
+ $this->assertEquals(1, $data['project_id']);
+ $this->assertEquals(1, $data['reference']);
+ $this->assertEquals('My new issue', $data['title']);
+ $this->assertEquals("**test**\n\n[Bitbucket Issue](https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue)", $data['description']);
+ }
+
+ public function onCommentCreatedWithNoUser($event)
+ {
+ $data = $event->getAll();
+ $this->assertEquals(1, $data['project_id']);
+ $this->assertEquals(1, $data['task_id']);
+ $this->assertEquals(0, $data['user_id']);
+ $this->assertEquals(19176252, $data['reference']);
+ $this->assertEquals("1. step1\n2. step2\n\n[By @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/issue/1#comment-19176252)", $data['comment']);
+ }
+
+ public function onCommentCreatedWithNotMember($event)
+ {
+ $data = $event->getAll();
+ $this->assertEquals(1, $data['project_id']);
+ $this->assertEquals(1, $data['task_id']);
+ $this->assertEquals(0, $data['user_id']);
+ $this->assertEquals(19176252, $data['reference']);
+ $this->assertEquals("1. step1\n2. step2\n\n[By @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/issue/1#comment-19176252)", $data['comment']);
+ }
+
+ public function onCommentCreatedWithUser($event)
+ {
+ $data = $event->getAll();
+ $this->assertEquals(1, $data['project_id']);
+ $this->assertEquals(1, $data['task_id']);
+ $this->assertEquals(2, $data['user_id']);
+ $this->assertEquals(19176252, $data['reference']);
+ $this->assertEquals("1. step1\n2. step2\n\n[By @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/issue/1#comment-19176252)", $data['comment']);
+ }
+
+ public function onIssueClosed($event)
+ {
+ $data = $event->getAll();
+ $this->assertEquals(1, $data['project_id']);
+ $this->assertEquals(1, $data['task_id']);
+ $this->assertEquals(1, $data['reference']);
+ }
+
+ public function onIssueReopened($event)
+ {
+ $data = $event->getAll();
+ $this->assertEquals(1, $data['project_id']);
+ $this->assertEquals(1, $data['task_id']);
+ $this->assertEquals(1, $data['reference']);
+ }
+
+ public function onIssueAssigned($event)
+ {
+ $data = $event->getAll();
+ $this->assertEquals(1, $data['project_id']);
+ $this->assertEquals(1, $data['task_id']);
+ $this->assertEquals(1, $data['reference']);
+ $this->assertEquals(2, $data['owner_id']);
+ }
+
+ public function onIssueUnassigned($event)
+ {
+ $data = $event->getAll();
+ $this->assertEquals(1, $data['project_id']);
+ $this->assertEquals(1, $data['task_id']);
+ $this->assertEquals(1, $data['reference']);
+ $this->assertEquals(0, $data['owner_id']);
}
}
diff --git a/tests/units/GithubWebhookTest.php b/tests/units/GithubWebhookTest.php
index 8d9d7144..e143cc1d 100644
--- a/tests/units/GithubWebhookTest.php
+++ b/tests/units/GithubWebhookTest.php
@@ -359,6 +359,7 @@ class GithubWebhookTest extends Base
$data = $event->getAll();
$this->assertEquals(1, $data['project_id']);
$this->assertEquals(3, $data['reference']);
+ $this->assertEquals('Test Webhook', $data['title']);
$this->assertEquals("plop\n\n[Github Issue](https://github.com/kanboardapp/webhook/issues/3)", $data['description']);
}
diff --git a/tests/units/fixtures/bitbucket_comment_created.json b/tests/units/fixtures/bitbucket_comment_created.json
new file mode 100644
index 00000000..66a09bb8
--- /dev/null
+++ b/tests/units/fixtures/bitbucket_comment_created.json
@@ -0,0 +1,147 @@
+{
+ "actor": {
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "display_name": "Frederic Guillot",
+ "type": "user",
+ "links": {
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ }
+ }
+ },
+ "repository": {
+ "full_name": "minicoders/test-webhook",
+ "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}",
+ "type": "repository",
+ "links": {
+ "avatar": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook"
+ }
+ },
+ "owner": {
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "display_name": "Frederic Guillot",
+ "type": "user",
+ "links": {
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ }
+ }
+ },
+ "name": "test-webhook"
+ },
+ "comment": {
+ "content": {
+ "html": "<ol>\n<li>step1</li>\n<li>step2</li>\n</ol>",
+ "raw": "1. step1\n2. step2",
+ "markup": "markdown"
+ },
+ "created_on": "2015-06-21T02:51:40.532529+00:00",
+ "links": {
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/issue/1#comment-19176252"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments/19176252"
+ }
+ },
+ "id": 19176252,
+ "user": {
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "display_name": "Frederic Guillot",
+ "type": "user",
+ "links": {
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ }
+ }
+ },
+ "updated_on": null
+ },
+ "issue": {
+ "updated_on": "2015-06-21T02:51:40.536516+00:00",
+ "votes": 0,
+ "assignee": null,
+ "links": {
+ "vote": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/vote"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1"
+ },
+ "watch": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/watch"
+ },
+ "comments": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments"
+ },
+ "attachments": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/attachments"
+ }
+ },
+ "priority": "major",
+ "kind": "bug",
+ "watches": 1,
+ "edited_on": null,
+ "state": "new",
+ "content": {
+ "html": "<p><strong>test</strong></p>",
+ "raw": "**test**",
+ "markup": "markdown"
+ },
+ "component": null,
+ "milestone": null,
+ "version": null,
+ "id": 1,
+ "created_on": "2015-06-21T02:17:40.990654+00:00",
+ "type": "issue",
+ "reporter": {
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "display_name": "Frederic Guillot",
+ "type": "user",
+ "links": {
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ }
+ }
+ },
+ "title": "My new issue"
+ }
+} \ No newline at end of file
diff --git a/tests/units/fixtures/bitbucket_issue_assigned.json b/tests/units/fixtures/bitbucket_issue_assigned.json
new file mode 100644
index 00000000..0324afb2
--- /dev/null
+++ b/tests/units/fixtures/bitbucket_issue_assigned.json
@@ -0,0 +1,209 @@
+{
+ "repository": {
+ "name": "test-webhook",
+ "type": "repository",
+ "full_name": "minicoders/test-webhook",
+ "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}",
+ "links": {
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook"
+ }
+ },
+ "owner": {
+ "display_name": "Frederic Guillot",
+ "type": "user",
+ "links": {
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ }
+ },
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}"
+ }
+ },
+ "changes": {
+ "responsible": {
+ "new": {
+ "is_system": false,
+ "name": "Frederic Guillot",
+ "username": "minicoders",
+ "id": 1290132,
+ "billing_external_uuid": null
+ },
+ "old": null
+ },
+ "assignee": {
+ "new": {
+ "display_name": "Frederic Guillot",
+ "type": "user",
+ "links": {
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ }
+ },
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}"
+ },
+ "old": null
+ }
+ },
+ "actor": {
+ "display_name": "Frederic Guillot",
+ "type": "user",
+ "links": {
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ }
+ },
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}"
+ },
+ "issue": {
+ "repository": {
+ "links": {
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook"
+ }
+ },
+ "type": "repository",
+ "full_name": "minicoders/test-webhook",
+ "name": "test-webhook",
+ "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}"
+ },
+ "edited_on": null,
+ "component": null,
+ "updated_on": "2015-06-21T15:21:28.023525+00:00",
+ "reporter": {
+ "display_name": "Frederic Guillot",
+ "type": "user",
+ "links": {
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ }
+ },
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}"
+ },
+ "state": "open",
+ "content": {
+ "raw": "**test**",
+ "markup": "markdown",
+ "html": "<p><strong>test</strong></p>"
+ },
+ "kind": "bug",
+ "links": {
+ "attachments": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/attachments"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue"
+ },
+ "watch": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/watch"
+ },
+ "vote": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/vote"
+ },
+ "comments": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1"
+ }
+ },
+ "created_on": "2015-06-21T02:17:40.990654+00:00",
+ "watches": 1,
+ "milestone": null,
+ "version": null,
+ "assignee": {
+ "display_name": "Frederic Guillot",
+ "type": "user",
+ "links": {
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ }
+ },
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}"
+ },
+ "title": "My new issue",
+ "priority": "major",
+ "id": 1,
+ "votes": 0,
+ "type": "issue"
+ },
+ "comment": {
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments/19181255"
+ }
+ },
+ "updated_on": null,
+ "content": {
+ "raw": null,
+ "markup": "markdown",
+ "html": ""
+ },
+ "id": 19181255,
+ "created_on": "2015-06-21T15:21:28.043980+00:00",
+ "user": {
+ "display_name": "Frederic Guillot",
+ "type": "user",
+ "links": {
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ }
+ },
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}"
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/units/fixtures/bitbucket_issue_closed.json b/tests/units/fixtures/bitbucket_issue_closed.json
new file mode 100644
index 00000000..473b5167
--- /dev/null
+++ b/tests/units/fixtures/bitbucket_issue_closed.json
@@ -0,0 +1,183 @@
+{
+ "actor": {
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "type": "user",
+ "display_name": "Frederic Guillot",
+ "links": {
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ }
+ }
+ },
+ "changes": {
+ "status": {
+ "old": "new",
+ "new": "closed"
+ }
+ },
+ "repository": {
+ "full_name": "minicoders/test-webhook",
+ "type": "repository",
+ "links": {
+ "avatar": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook"
+ }
+ },
+ "owner": {
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "type": "user",
+ "display_name": "Frederic Guillot",
+ "links": {
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ }
+ }
+ },
+ "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}",
+ "name": "test-webhook"
+ },
+ "comment": {
+ "content": {
+ "html": "",
+ "raw": null,
+ "markup": "markdown"
+ },
+ "created_on": "2015-06-21T02:54:40.263014+00:00",
+ "updated_on": null,
+ "id": 19176265,
+ "user": {
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "type": "user",
+ "display_name": "Frederic Guillot",
+ "links": {
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ }
+ }
+ },
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments/19176265"
+ }
+ }
+ },
+ "issue": {
+ "state": "closed",
+ "votes": 0,
+ "assignee": {
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "type": "user",
+ "display_name": "Frederic Guillot",
+ "links": {
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ }
+ }
+ },
+ "links": {
+ "vote": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/vote"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1"
+ },
+ "watch": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/watch"
+ },
+ "comments": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments"
+ },
+ "attachments": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/attachments"
+ }
+ },
+ "priority": "major",
+ "version": null,
+ "watches": 1,
+ "edited_on": null,
+ "reporter": {
+ "username": "minicoders",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "type": "user",
+ "display_name": "Frederic Guillot",
+ "links": {
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ }
+ }
+ },
+ "content": {
+ "html": "<p><strong>test</strong></p>",
+ "raw": "**test**",
+ "markup": "markdown"
+ },
+ "component": null,
+ "created_on": "2015-06-21T02:17:40.990654+00:00",
+ "updated_on": "2015-06-21T02:54:40.249466+00:00",
+ "kind": "bug",
+ "id": 1,
+ "milestone": null,
+ "type": "issue",
+ "repository": {
+ "full_name": "minicoders/test-webhook",
+ "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}",
+ "type": "repository",
+ "name": "test-webhook",
+ "links": {
+ "avatar": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook"
+ }
+ }
+ },
+ "title": "My new issue"
+ }
+} \ No newline at end of file
diff --git a/tests/units/fixtures/bitbucket_issue_opened.json b/tests/units/fixtures/bitbucket_issue_opened.json
new file mode 100644
index 00000000..7891c230
--- /dev/null
+++ b/tests/units/fixtures/bitbucket_issue_opened.json
@@ -0,0 +1,112 @@
+{
+ "issue": {
+ "type": "issue",
+ "links": {
+ "attachments": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/attachments"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue"
+ },
+ "comments": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments"
+ },
+ "vote": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/vote"
+ },
+ "watch": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/watch"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1"
+ }
+ },
+ "component": null,
+ "updated_on": "2015-06-21T02:17:40.990654+00:00",
+ "reporter": {
+ "links": {
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ }
+ },
+ "username": "minicoders",
+ "type": "user",
+ "display_name": "Frederic Guillot",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}"
+ },
+ "watches": 1,
+ "kind": "bug",
+ "edited_on": null,
+ "created_on": "2015-06-21T02:17:40.990654+00:00",
+ "milestone": null,
+ "version": null,
+ "state": "new",
+ "assignee": null,
+ "content": {
+ "raw": "**test**",
+ "markup": "markdown",
+ "html": "<p><strong>test</strong></p>"
+ },
+ "priority": "major",
+ "id": 1,
+ "votes": 0,
+ "title": "My new issue"
+ },
+ "repository": {
+ "links": {
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook"
+ }
+ },
+ "type": "repository",
+ "full_name": "minicoders/test-webhook",
+ "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}",
+ "name": "test-webhook",
+ "owner": {
+ "links": {
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ }
+ },
+ "username": "minicoders",
+ "type": "user",
+ "display_name": "Frederic Guillot",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}"
+ }
+ },
+ "actor": {
+ "links": {
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ }
+ },
+ "username": "minicoders",
+ "type": "user",
+ "display_name": "Frederic Guillot",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}"
+ }
+} \ No newline at end of file
diff --git a/tests/units/fixtures/bitbucket_issue_reopened.json b/tests/units/fixtures/bitbucket_issue_reopened.json
new file mode 100644
index 00000000..bb950916
--- /dev/null
+++ b/tests/units/fixtures/bitbucket_issue_reopened.json
@@ -0,0 +1,183 @@
+{
+ "issue": {
+ "edited_on": null,
+ "watches": 1,
+ "created_on": "2015-06-21T02:17:40.990654+00:00",
+ "reporter": {
+ "username": "minicoders",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ }
+ },
+ "display_name": "Frederic Guillot",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "type": "user"
+ },
+ "content": {
+ "markup": "markdown",
+ "raw": "**test**",
+ "html": "<p><strong>test</strong></p>"
+ },
+ "id": 1,
+ "milestone": null,
+ "repository": {
+ "full_name": "minicoders/test-webhook",
+ "type": "repository",
+ "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/"
+ }
+ },
+ "name": "test-webhook"
+ },
+ "component": null,
+ "version": null,
+ "votes": 0,
+ "priority": "major",
+ "type": "issue",
+ "state": "open",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1"
+ },
+ "comments": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue"
+ },
+ "watch": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/watch"
+ },
+ "attachments": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/attachments"
+ },
+ "vote": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/vote"
+ }
+ },
+ "kind": "bug",
+ "updated_on": "2015-06-21T14:56:49.739063+00:00",
+ "assignee": {
+ "username": "minicoders",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ }
+ },
+ "display_name": "Frederic Guillot",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "type": "user"
+ },
+ "title": "My new issue"
+ },
+ "comment": {
+ "id": 19181022,
+ "created_on": "2015-06-21T14:56:49.749362+00:00",
+ "content": {
+ "markup": "markdown",
+ "raw": null,
+ "html": ""
+ },
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments/19181022"
+ }
+ },
+ "user": {
+ "username": "minicoders",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ }
+ },
+ "display_name": "Frederic Guillot",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "type": "user"
+ },
+ "updated_on": null
+ },
+ "repository": {
+ "name": "test-webhook",
+ "owner": {
+ "username": "minicoders",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ }
+ },
+ "display_name": "Frederic Guillot",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "type": "user"
+ },
+ "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}",
+ "type": "repository",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/"
+ }
+ },
+ "full_name": "minicoders/test-webhook"
+ },
+ "changes": {
+ "status": {
+ "new": "open",
+ "old": "closed"
+ }
+ },
+ "actor": {
+ "username": "minicoders",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ }
+ },
+ "display_name": "Frederic Guillot",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "type": "user"
+ }
+} \ No newline at end of file
diff --git a/tests/units/fixtures/bitbucket_issue_unassigned.json b/tests/units/fixtures/bitbucket_issue_unassigned.json
new file mode 100644
index 00000000..3cbab2ea
--- /dev/null
+++ b/tests/units/fixtures/bitbucket_issue_unassigned.json
@@ -0,0 +1,193 @@
+{
+ "comment": {
+ "updated_on": null,
+ "content": {
+ "html": "",
+ "markup": "markdown",
+ "raw": null
+ },
+ "created_on": "2015-06-21T15:07:45.787623+00:00",
+ "user": {
+ "display_name": "Frederic Guillot",
+ "username": "minicoders",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ }
+ },
+ "type": "user",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}"
+ },
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments/19181143"
+ }
+ },
+ "id": 19181143
+ },
+ "issue": {
+ "state": "open",
+ "content": {
+ "html": "<p><strong>test</strong></p>",
+ "markup": "markdown",
+ "raw": "**test**"
+ },
+ "milestone": null,
+ "type": "issue",
+ "version": null,
+ "title": "My new issue",
+ "assignee": null,
+ "kind": "bug",
+ "component": null,
+ "priority": "major",
+ "reporter": {
+ "display_name": "Frederic Guillot",
+ "username": "minicoders",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ }
+ },
+ "type": "user",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}"
+ },
+ "created_on": "2015-06-21T02:17:40.990654+00:00",
+ "edited_on": null,
+ "updated_on": "2015-06-21T15:07:45.775705+00:00",
+ "id": 1,
+ "votes": 0,
+ "repository": {
+ "full_name": "minicoders/test-webhook",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook"
+ }
+ },
+ "type": "repository",
+ "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}",
+ "name": "test-webhook"
+ },
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1"
+ },
+ "watch": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/watch"
+ },
+ "vote": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/vote"
+ },
+ "comments": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue"
+ },
+ "attachments": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/attachments"
+ }
+ },
+ "watches": 1
+ },
+ "actor": {
+ "display_name": "Frederic Guillot",
+ "username": "minicoders",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ }
+ },
+ "type": "user",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}"
+ },
+ "repository": {
+ "full_name": "minicoders/test-webhook",
+ "owner": {
+ "display_name": "Frederic Guillot",
+ "username": "minicoders",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ }
+ },
+ "type": "user",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}"
+ },
+ "type": "repository",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook"
+ }
+ },
+ "name": "test-webhook",
+ "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}"
+ },
+ "changes": {
+ "responsible": {
+ "old": {
+ "is_system": false,
+ "username": "minicoders",
+ "name": "Frederic Guillot",
+ "billing_external_uuid": null,
+ "id": 1290132
+ },
+ "new": null
+ },
+ "assignee": {
+ "old": {
+ "display_name": "Frederic Guillot",
+ "username": "minicoders",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ }
+ },
+ "type": "user",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}"
+ },
+ "new": null
+ }
+ }
+} \ No newline at end of file
diff --git a/tests/units/fixtures/bitbucket_push.json b/tests/units/fixtures/bitbucket_push.json
new file mode 100644
index 00000000..f480b074
--- /dev/null
+++ b/tests/units/fixtures/bitbucket_push.json
@@ -0,0 +1,182 @@
+{
+ "push": {
+ "changes": [
+ {
+ "forced": false,
+ "old": {
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/refs/branches/master"
+ },
+ "commits": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/commits/master"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/branch/master"
+ }
+ },
+ "name": "master",
+ "target": {
+ "date": "2015-06-21T00:50:37+00:00",
+ "hash": "b6b46580eb9b20a06396f5f697ea1a55cf170e69",
+ "message": "test edited online with Bitbucket for task #5",
+ "type": "commit",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/commit/b6b46580eb9b20a06396f5f697ea1a55cf170e69"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/commits/b6b46580eb9b20a06396f5f697ea1a55cf170e69"
+ }
+ },
+ "parents": [
+ {
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/commit/7251db4b505cbfca3f845ebcff0ec0ddc4003ed8"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/commits/7251db4b505cbfca3f845ebcff0ec0ddc4003ed8"
+ }
+ },
+ "type": "commit",
+ "hash": "7251db4b505cbfca3f845ebcff0ec0ddc4003ed8"
+ }
+ ],
+ "author": {
+ "raw": "Frederic Guillot <bob>",
+ "user": {
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ }
+ },
+ "type": "user",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "username": "minicoders",
+ "display_name": "Frederic Guillot"
+ }
+ }
+ },
+ "type": "branch"
+ },
+ "created": false,
+ "links": {
+ "diff": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/diff/824059cce7667d3f8d8780cc707391be821e0ea6..b6b46580eb9b20a06396f5f697ea1a55cf170e69"
+ },
+ "commits": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/commits?include=824059cce7667d3f8d8780cc707391be821e0ea6exclude=b6b46580eb9b20a06396f5f697ea1a55cf170e69"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/branches/compare/824059cce7667d3f8d8780cc707391be821e0ea6..b6b46580eb9b20a06396f5f697ea1a55cf170e69"
+ }
+ },
+ "new": {
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/refs/branches/master"
+ },
+ "commits": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/commits/master"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/branch/master"
+ }
+ },
+ "name": "master",
+ "target": {
+ "date": "2015-06-21T03:15:08+00:00",
+ "hash": "824059cce7667d3f8d8780cc707391be821e0ea6",
+ "message": "Test another commit #2\n",
+ "type": "commit",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/commit/824059cce7667d3f8d8780cc707391be821e0ea6"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6"
+ }
+ },
+ "parents": [
+ {
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/commit/24aa9d82bbb6f9a60f743fe538deb0a44622fc98"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/commits/24aa9d82bbb6f9a60f743fe538deb0a44622fc98"
+ }
+ },
+ "type": "commit",
+ "hash": "24aa9d82bbb6f9a60f743fe538deb0a44622fc98"
+ }
+ ],
+ "author": {
+ "raw": "Frederic Guillot <bob@localhost>"
+ }
+ },
+ "type": "branch"
+ },
+ "closed": false
+ }
+ ]
+ },
+ "repository": {
+ "name": "test-webhook",
+ "owner": {
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ }
+ },
+ "type": "user",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "username": "minicoders",
+ "display_name": "Frederic Guillot"
+ },
+ "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}",
+ "type": "repository",
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders/test-webhook"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/"
+ }
+ },
+ "full_name": "minicoders/test-webhook"
+ },
+ "actor": {
+ "links": {
+ "self": {
+ "href": "https://bitbucket.org/api/2.0/users/minicoders"
+ },
+ "html": {
+ "href": "https://bitbucket.org/minicoders"
+ },
+ "avatar": {
+ "href": "https://bitbucket.org/account/minicoders/avatar/32/"
+ }
+ },
+ "type": "user",
+ "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}",
+ "username": "minicoders",
+ "display_name": "Frederic Guillot"
+ }
+} \ No newline at end of file