summaryrefslogtreecommitdiff
path: root/app/Action
diff options
context:
space:
mode:
Diffstat (limited to 'app/Action')
-rw-r--r--app/Action/ActionCommentCreationTest.php53
-rw-r--r--app/Action/CommentCreation.php13
2 files changed, 61 insertions, 5 deletions
diff --git a/app/Action/ActionCommentCreationTest.php b/app/Action/ActionCommentCreationTest.php
index 6531c5b3..a4ca284e 100644
--- a/app/Action/ActionCommentCreationTest.php
+++ b/app/Action/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->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);
diff --git a/app/Action/CommentCreation.php b/app/Action/CommentCreation.php
index 44deb819..fb9f1172 100644
--- a/app/Action/CommentCreation.php
+++ b/app/Action/CommentCreation.php
@@ -2,7 +2,9 @@
namespace Action;
+use Integration\BitbucketWebhook;
use Integration\GithubWebhook;
+use Integration\GitlabWebhook;
/**
* Create automatically a comment from a webhook
@@ -22,6 +24,9 @@ class CommentCreation extends Base
{
return array(
GithubWebhook::EVENT_ISSUE_COMMENT,
+ GithubWebhook::EVENT_COMMIT,
+ BitbucketWebhook::EVENT_COMMIT,
+ GitlabWebhook::EVENT_COMMIT,
);
}
@@ -45,8 +50,6 @@ class CommentCreation extends Base
public function getEventRequiredParameters()
{
return array(
- 'comment',
- 'user_id',
'task_id',
);
}
@@ -62,9 +65,9 @@ class CommentCreation extends Base
{
return (bool) $this->comment->create(array(
'reference' => isset($data['reference']) ? $data['reference'] : '',
- 'comment' => $data['comment'],
+ 'comment' => empty($data['comment']) ? $data['commit_comment'] : $data['comment'],
'task_id' => $data['task_id'],
- 'user_id' => $data['user_id'],
+ 'user_id' => empty($data['user_id']) ? 0 : $data['user_id'],
));
}
@@ -77,6 +80,6 @@ class CommentCreation extends Base
*/
public function hasRequiredCondition(array $data)
{
- return true;
+ return ! empty($data['comment']) || ! empty($data['commit_comment']);
}
}