summaryrefslogtreecommitdiff
path: root/app/Action/TaskAssignCategoryLabel.php
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/TaskAssignCategoryLabel.php
parent03fa01ac7b036820ee232d893ec63241918c6012 (diff)
Add support for Github Issue Webhooks
Diffstat (limited to 'app/Action/TaskAssignCategoryLabel.php')
-rw-r--r--app/Action/TaskAssignCategoryLabel.php84
1 files changed, 84 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');
+ }
+}