diff options
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/Action.php | 2 | ||||
-rw-r--r-- | app/Model/GithubWebhook.php | 87 |
2 files changed, 75 insertions, 14 deletions
diff --git a/app/Model/Action.php b/app/Model/Action.php index 56a1a2bb..c3acdc5b 100644 --- a/app/Model/Action.php +++ b/app/Model/Action.php @@ -46,6 +46,7 @@ class Action extends Base 'TaskAssignColorUser' => t('Assign a color to a specific user'), 'TaskAssignColorCategory' => t('Assign automatically a color based on a category'), 'TaskAssignCategoryColor' => t('Assign automatically a category based on a color'), + 'CommentCreation' => t('Create a comment from an external provider'), 'TaskCreation' => t('Create a task from an external provider'), 'TaskAssignUser' => t('Change the assignee based on an external username'), 'TaskAssignCategoryLabel' => t('Change the category based on an external label'), @@ -78,6 +79,7 @@ class Action extends Base GithubWebhook::EVENT_ISSUE_REOPENED => t('Github issue reopened'), GithubWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE => t('Github issue assignee change'), GithubWebhook::EVENT_ISSUE_LABEL_CHANGE => t('Github issue label change'), + GithubWebhook::EVENT_ISSUE_COMMENT => t('Github issue comment created'), ); asort($values); diff --git a/app/Model/GithubWebhook.php b/app/Model/GithubWebhook.php index 6624a782..58c2fa54 100644 --- a/app/Model/GithubWebhook.php +++ b/app/Model/GithubWebhook.php @@ -48,6 +48,7 @@ class GithubWebhook extends Base * @access public * @param string $type Github event type * @param string $payload Raw Github event (JSON) + * @return boolean */ public function parsePayload($type, $payload) { @@ -58,7 +59,11 @@ class GithubWebhook extends Base return $this->parsePushEvent($payload); case 'issues': return $this->parseIssueEvent($payload); + case 'issue_comment': + return $this->parseCommentIssueEvent($payload); } + + return false; } /** @@ -66,6 +71,7 @@ class GithubWebhook extends Base * * @access public * @param array $payload Event data + * @return boolean */ public function parsePushEvent(array $payload) { @@ -87,6 +93,8 @@ class GithubWebhook extends Base $this->event->trigger(self::EVENT_COMMIT, array('task_id' => $task_id) + $task); } } + + return true; } /** @@ -94,32 +102,57 @@ class GithubWebhook extends Base * * @access public * @param array $payload Event data + * @return boolean */ public function parseIssueEvent(array $payload) { switch ($payload['action']) { case 'opened': - $this->handleIssueOpened($payload['issue']); - break; + return $this->handleIssueOpened($payload['issue']); case 'closed': - $this->handleIssueClosed($payload['issue']); - break; + return $this->handleIssueClosed($payload['issue']); case 'reopened': - $this->handleIssueReopened($payload['issue']); - break; + return $this->handleIssueReopened($payload['issue']); case 'assigned': - $this->handleIssueAssigned($payload['issue']); - break; + return $this->handleIssueAssigned($payload['issue']); case 'unassigned': - $this->handleIssueUnassigned($payload['issue']); - break; + return $this->handleIssueUnassigned($payload['issue']); case 'labeled': - $this->handleIssueLabeled($payload['issue'], $payload['label']); - break; + return $this->handleIssueLabeled($payload['issue'], $payload['label']); case 'unlabeled': - $this->handleIssueUnlabeled($payload['issue'], $payload['label']); - break; + return $this->handleIssueUnlabeled($payload['issue'], $payload['label']); + } + + return false; + } + + /** + * Parse comment issue events + * + * @access public + * @param array $payload Event data + * @return boolean + */ + public function parseCommentIssueEvent(array $payload) + { + $task = $this->taskFinder->getByReference($payload['issue']['number']); + $user = $this->user->getByUsername($payload['comment']['user']['login']); + + if ($task && $user) { + + $event = array( + 'project_id' => $this->project_id, + 'reference' => $payload['comment']['id'], + 'comment' => $payload['comment']['body'], + 'user_id' => $user['id'], + 'task_id' => $task['id'], + ); + + $this->event->trigger(self::EVENT_ISSUE_COMMENT, $event); + return true; } + + return false; } /** @@ -127,6 +160,7 @@ class GithubWebhook extends Base * * @access public * @param array $issue Issue data + * @return boolean */ public function handleIssueOpened(array $issue) { @@ -138,6 +172,7 @@ class GithubWebhook extends Base ); $this->event->trigger(self::EVENT_ISSUE_OPENED, $event); + return true; } /** @@ -145,6 +180,7 @@ class GithubWebhook extends Base * * @access public * @param array $issue Issue data + * @return boolean */ public function handleIssueClosed(array $issue) { @@ -158,7 +194,10 @@ class GithubWebhook extends Base ); $this->event->trigger(self::EVENT_ISSUE_CLOSED, $event); + return true; } + + return false; } /** @@ -166,6 +205,7 @@ class GithubWebhook extends Base * * @access public * @param array $issue Issue data + * @return boolean */ public function handleIssueReopened(array $issue) { @@ -179,7 +219,10 @@ class GithubWebhook extends Base ); $this->event->trigger(self::EVENT_ISSUE_REOPENED, $event); + return true; } + + return false; } /** @@ -187,6 +230,7 @@ class GithubWebhook extends Base * * @access public * @param array $issue Issue data + * @return boolean */ public function handleIssueAssigned(array $issue) { @@ -203,7 +247,10 @@ class GithubWebhook extends Base ); $this->event->trigger(self::EVENT_ISSUE_ASSIGNEE_CHANGE, $event); + return true; } + + return false; } /** @@ -211,6 +258,7 @@ class GithubWebhook extends Base * * @access public * @param array $issue Issue data + * @return boolean */ public function handleIssueUnassigned(array $issue) { @@ -226,7 +274,10 @@ class GithubWebhook extends Base ); $this->event->trigger(self::EVENT_ISSUE_ASSIGNEE_CHANGE, $event); + return true; } + + return false; } /** @@ -235,6 +286,7 @@ class GithubWebhook extends Base * @access public * @param array $issue Issue data * @param array $label Label data + * @return boolean */ public function handleIssueLabeled(array $issue, array $label) { @@ -250,7 +302,10 @@ class GithubWebhook extends Base ); $this->event->trigger(self::EVENT_ISSUE_LABEL_CHANGE, $event); + return true; } + + return false; } /** @@ -259,6 +314,7 @@ class GithubWebhook extends Base * @access public * @param array $issue Issue data * @param array $label Label data + * @return boolean */ public function handleIssueUnlabeled(array $issue, array $label) { @@ -275,6 +331,9 @@ class GithubWebhook extends Base ); $this->event->trigger(self::EVENT_ISSUE_LABEL_CHANGE, $event); + return true; } + + return false; } } |