summaryrefslogtreecommitdiff
path: root/app/Action
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-09-28 18:23:21 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-09-28 18:23:21 -0400
commit33f9cdbc976e0f97c3dd24658dc7d0097497c6d7 (patch)
tree3a5dc8ca9a6b3db268ba95aec357a2e5a8aad80e /app/Action
parent03fa01ac7b036820ee232d893ec63241918c6012 (diff)
Add support for Github Issue Webhooks
Diffstat (limited to 'app/Action')
-rw-r--r--app/Action/TaskAssignCategoryLabel.php84
-rw-r--r--app/Action/TaskAssignUser.php81
-rw-r--r--app/Action/TaskClose.php4
-rw-r--r--app/Action/TaskCreation.php81
-rw-r--r--app/Action/TaskOpen.php73
5 files changed, 323 insertions, 0 deletions
diff --git a/app/Action/TaskAssignCategoryLabel.php b/app/Action/TaskAssignCategoryLabel.php
new file mode 100644
index 00000000..5e1b025e
--- /dev/null
+++ b/app/Action/TaskAssignCategoryLabel.php
@@ -0,0 +1,84 @@
+<?php
+
+namespace Action;
+
+use Model\GithubWebhook;
+
+/**
+ * Set a category automatically according to a label
+ *
+ * @package action
+ * @author Frederic Guillot
+ */
+class TaskAssignCategoryLabel extends Base
+{
+ /**
+ * Get the list of compatible events
+ *
+ * @access public
+ * @return array
+ */
+ public function getCompatibleEvents()
+ {
+ return array(
+ GithubWebhook::EVENT_ISSUE_LABEL_CHANGE,
+ );
+ }
+
+ /**
+ * Get the required parameter for the action (defined by the user)
+ *
+ * @access public
+ * @return array
+ */
+ public function getActionRequiredParameters()
+ {
+ return array(
+ 'label' => t('Label'),
+ 'category_id' => t('Category'),
+ );
+ }
+
+ /**
+ * Get the required parameter for the event
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getEventRequiredParameters()
+ {
+ return array(
+ 'task_id',
+ 'label',
+ );
+ }
+
+ /**
+ * Execute the action (change the category)
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool True if the action was executed or false when not executed
+ */
+ public function doAction(array $data)
+ {
+ $values = array(
+ 'id' => $data['task_id'],
+ 'category_id' => isset($data['category_id']) ? $data['category_id'] : $this->getParam('category_id'),
+ );
+
+ return $this->task->update($values, false);
+ }
+
+ /**
+ * Check if the event data meet the action condition
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool
+ */
+ public function hasRequiredCondition(array $data)
+ {
+ return $data['label'] == $this->getParam('label');
+ }
+}
diff --git a/app/Action/TaskAssignUser.php b/app/Action/TaskAssignUser.php
new file mode 100644
index 00000000..29ea91e6
--- /dev/null
+++ b/app/Action/TaskAssignUser.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace Action;
+
+use Model\GithubWebhook;
+
+/**
+ * Assign a task to someone
+ *
+ * @package action
+ * @author Frederic Guillot
+ */
+class TaskAssignUser extends Base
+{
+ /**
+ * Get the list of compatible events
+ *
+ * @access public
+ * @return array
+ */
+ public function getCompatibleEvents()
+ {
+ return array(
+ GithubWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE,
+ );
+ }
+
+ /**
+ * Get the required parameter for the action (defined by the user)
+ *
+ * @access public
+ * @return array
+ */
+ public function getActionRequiredParameters()
+ {
+ return array();
+ }
+
+ /**
+ * Get the required parameter for the event
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getEventRequiredParameters()
+ {
+ return array(
+ 'task_id',
+ 'owner_id',
+ );
+ }
+
+ /**
+ * Execute the action (assign the given user)
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool True if the action was executed or false when not executed
+ */
+ public function doAction(array $data)
+ {
+ $values = array(
+ 'id' => $data['task_id'],
+ 'owner_id' => $data['owner_id'],
+ );
+
+ return $this->task->update($values, false);
+ }
+
+ /**
+ * Check if the event data meet the action condition
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool
+ */
+ public function hasRequiredCondition(array $data)
+ {
+ return true;
+ }
+}
diff --git a/app/Action/TaskClose.php b/app/Action/TaskClose.php
index da0744d0..f71d4b0e 100644
--- a/app/Action/TaskClose.php
+++ b/app/Action/TaskClose.php
@@ -24,6 +24,7 @@ class TaskClose extends Base
return array(
Task::EVENT_MOVE_COLUMN,
GithubWebhook::EVENT_COMMIT,
+ GithubWebhook::EVENT_ISSUE_CLOSED,
);
}
@@ -37,6 +38,7 @@ class TaskClose extends Base
{
switch ($this->event_name) {
case GithubWebhook::EVENT_COMMIT:
+ case GithubWebhook::EVENT_ISSUE_CLOSED:
return array();
default:
return array('column_id' => t('Column'));
@@ -53,6 +55,7 @@ class TaskClose extends Base
{
switch ($this->event_name) {
case GithubWebhook::EVENT_COMMIT:
+ case GithubWebhook::EVENT_ISSUE_CLOSED:
return array('task_id');
default:
return array('task_id', 'column_id');
@@ -82,6 +85,7 @@ class TaskClose extends Base
{
switch ($this->event_name) {
case GithubWebhook::EVENT_COMMIT:
+ case GithubWebhook::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
new file mode 100644
index 00000000..41d0200c
--- /dev/null
+++ b/app/Action/TaskCreation.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace Action;
+
+use Model\GithubWebhook;
+
+/**
+ * Create automatically a task from a webhook
+ *
+ * @package action
+ * @author Frederic Guillot
+ */
+class TaskCreation extends Base
+{
+ /**
+ * Get the list of compatible events
+ *
+ * @access public
+ * @return array
+ */
+ public function getCompatibleEvents()
+ {
+ return array(
+ GithubWebhook::EVENT_ISSUE_OPENED,
+ );
+ }
+
+ /**
+ * Get the required parameter for the action (defined by the user)
+ *
+ * @access public
+ * @return array
+ */
+ public function getActionRequiredParameters()
+ {
+ return array();
+ }
+
+ /**
+ * Get the required parameter for the event
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getEventRequiredParameters()
+ {
+ return array(
+ 'reference',
+ 'title',
+ );
+ }
+
+ /**
+ * Execute the action (create a new task)
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool True if the action was executed or false when not executed
+ */
+ public function doAction(array $data)
+ {
+ return $this->task->create(array(
+ 'project_id' => $data['project_id'],
+ 'title' => $data['title'],
+ 'reference' => $data['reference'],
+ 'description' => $data['description'],
+ ));
+ }
+
+ /**
+ * Check if the event data meet the action condition
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool
+ */
+ public function hasRequiredCondition(array $data)
+ {
+ return true;
+ }
+}
diff --git a/app/Action/TaskOpen.php b/app/Action/TaskOpen.php
new file mode 100644
index 00000000..6847856c
--- /dev/null
+++ b/app/Action/TaskOpen.php
@@ -0,0 +1,73 @@
+<?php
+
+namespace Action;
+
+use Model\GithubWebhook;
+
+/**
+ * Open automatically a task
+ *
+ * @package action
+ * @author Frederic Guillot
+ */
+class TaskOpen extends Base
+{
+ /**
+ * Get the list of compatible events
+ *
+ * @access public
+ * @return array
+ */
+ public function getCompatibleEvents()
+ {
+ return array(
+ GithubWebhook::EVENT_ISSUE_REOPENED,
+ );
+ }
+
+ /**
+ * Get the required parameter for the action (defined by the user)
+ *
+ * @access public
+ * @return array
+ */
+ public function getActionRequiredParameters()
+ {
+ return array();
+ }
+
+ /**
+ * Get the required parameter for the event
+ *
+ * @access public
+ * @return string[]
+ */
+ public function getEventRequiredParameters()
+ {
+ return array('task_id');
+ }
+
+ /**
+ * Execute the action (close the task)
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool True if the action was executed or false when not executed
+ */
+ public function doAction(array $data)
+ {
+ return $this->task->open($data['task_id']);
+ }
+
+ /**
+ * Check if the event data meet the action condition
+ *
+ * @access public
+ * @param array $data Event data dictionary
+ * @return bool
+ */
+ public function hasRequiredCondition(array $data)
+ {
+ return true;
+ }
+}