Update Bitbucket webhooks to handle issues/commit/comments
This commit is contained in:
@@ -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']);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user