From 33f9cdbc976e0f97c3dd24658dc7d0097497c6d7 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 28 Sep 2014 18:23:21 -0400 Subject: Add support for Github Issue Webhooks --- app/Action/TaskAssignCategoryLabel.php | 84 ++++++++++++++++++++++++++++++++++ app/Action/TaskAssignUser.php | 81 ++++++++++++++++++++++++++++++++ app/Action/TaskClose.php | 4 ++ app/Action/TaskCreation.php | 81 ++++++++++++++++++++++++++++++++ app/Action/TaskOpen.php | 73 +++++++++++++++++++++++++++++ 5 files changed, 323 insertions(+) create mode 100644 app/Action/TaskAssignCategoryLabel.php create mode 100644 app/Action/TaskAssignUser.php create mode 100644 app/Action/TaskCreation.php create mode 100644 app/Action/TaskOpen.php (limited to 'app/Action') 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 @@ + 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 @@ + $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 @@ +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 @@ +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; + } +} -- cgit v1.2.3