From 5266b821446b14b79a3c5a5c77c57791b985f0a9 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 28 Dec 2014 22:22:15 -0500 Subject: Add Gitlab webhook --- app/Model/Acl.php | 2 +- app/Model/Action.php | 5 + app/Model/Base.php | 1 + app/Model/GithubWebhook.php | 374 -------------------------------------------- 4 files changed, 7 insertions(+), 375 deletions(-) delete mode 100644 app/Model/GithubWebhook.php (limited to 'app/Model') diff --git a/app/Model/Acl.php b/app/Model/Acl.php index 3f454885..d294197a 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -21,7 +21,7 @@ class Acl extends Base 'task' => array('readonly'), 'board' => array('readonly'), 'project' => array('feed'), - 'webhook' => array('task', 'github'), + 'webhook' => array('task', 'github', 'gitlab'), ); /** diff --git a/app/Model/Action.php b/app/Model/Action.php index 36e0aa62..905b8914 100644 --- a/app/Model/Action.php +++ b/app/Model/Action.php @@ -2,6 +2,8 @@ namespace Model; +use Integration\GitlabWebhook; +use Integration\GithubWebhook; use SimpleValidator\Validator; use SimpleValidator\Validators; @@ -79,6 +81,9 @@ class Action extends Base 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'), + GitlabWebhook::EVENT_COMMIT => t('Gitlab commit received'), + GitlabWebhook::EVENT_ISSUE_OPENED => t('Gitlab issue opened'), + GitlabWebhook::EVENT_ISSUE_CLOSED => t('Gitlab issue closed'), ); asort($values); diff --git a/app/Model/Base.php b/app/Model/Base.php index dfac12ae..db670969 100644 --- a/app/Model/Base.php +++ b/app/Model/Base.php @@ -29,6 +29,7 @@ use Pimple\Container; * @property \Model\ProjectPermission $projectPermission * @property \Model\SubTask $subTask * @property \Model\SubtaskHistory $subtaskHistory + * @property \Model\Swimlane $swimlane * @property \Model\Task $task * @property \Model\TaskCreation $taskCreation * @property \Model\TaskExport $taskExport diff --git a/app/Model/GithubWebhook.php b/app/Model/GithubWebhook.php deleted file mode 100644 index f66358eb..00000000 --- a/app/Model/GithubWebhook.php +++ /dev/null @@ -1,374 +0,0 @@ -project_id = $project_id; - } - - /** - * Parse Github events - * - * @access public - * @param string $type Github event type - * @param array $payload Github event - * @return boolean - */ - public function parsePayload($type, array $payload) - { - switch ($type) { - case 'push': - return $this->parsePushEvent($payload); - case 'issues': - return $this->parseIssueEvent($payload); - case 'issue_comment': - return $this->parseCommentIssueEvent($payload); - } - - return false; - } - - /** - * Parse Push events (list of commits) - * - * @access public - * @param array $payload Event data - * @return boolean - */ - public function parsePushEvent(array $payload) - { - foreach ($payload['commits'] as $commit) { - - $task_id = $this->task->getTaskIdFromText($commit['message']); - - if (! $task_id) { - continue; - } - - $task = $this->taskFinder->getById($task_id); - - if (! $task) { - continue; - } - - if ($task['is_active'] == Task::STATUS_OPEN) { - $this->container['dispatcher']->dispatch( - self::EVENT_COMMIT, - new GenericEvent(array('task_id' => $task_id) + $task) - ); - } - } - - return true; - } - - /** - * Parse issue events - * - * @access public - * @param array $payload Event data - * @return boolean - */ - public function parseIssueEvent(array $payload) - { - switch ($payload['action']) { - case 'opened': - return $this->handleIssueOpened($payload['issue']); - case 'closed': - return $this->handleIssueClosed($payload['issue']); - case 'reopened': - return $this->handleIssueReopened($payload['issue']); - case 'assigned': - return $this->handleIssueAssigned($payload['issue']); - case 'unassigned': - return $this->handleIssueUnassigned($payload['issue']); - case 'labeled': - return $this->handleIssueLabeled($payload['issue'], $payload['label']); - case 'unlabeled': - 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->container['dispatcher']->dispatch( - self::EVENT_ISSUE_COMMENT, - new GenericEvent($event) - ); - - return true; - } - - return false; - } - - /** - * Handle new issues - * - * @access public - * @param array $issue Issue data - * @return boolean - */ - public function handleIssueOpened(array $issue) - { - $event = array( - 'project_id' => $this->project_id, - 'reference' => $issue['number'], - 'title' => $issue['title'], - 'description' => $issue['body']."\n\n[".t('Github Issue').']('.$issue['html_url'].')', - ); - - $this->container['dispatcher']->dispatch( - self::EVENT_ISSUE_OPENED, - new GenericEvent($event) - ); - - return true; - } - - /** - * Handle issue closing - * - * @access public - * @param array $issue Issue data - * @return boolean - */ - public function handleIssueClosed(array $issue) - { - $task = $this->taskFinder->getByReference($issue['number']); - - if ($task) { - $event = array( - 'project_id' => $this->project_id, - 'task_id' => $task['id'], - 'reference' => $issue['number'], - ); - - $this->container['dispatcher']->dispatch( - self::EVENT_ISSUE_CLOSED, - new GenericEvent($event) - ); - - return true; - } - - return false; - } - - /** - * Handle issue reopened - * - * @access public - * @param array $issue Issue data - * @return boolean - */ - public function handleIssueReopened(array $issue) - { - $task = $this->taskFinder->getByReference($issue['number']); - - if ($task) { - $event = array( - 'project_id' => $this->project_id, - 'task_id' => $task['id'], - 'reference' => $issue['number'], - ); - - $this->container['dispatcher']->dispatch( - self::EVENT_ISSUE_REOPENED, - new GenericEvent($event) - ); - - return true; - } - - return false; - } - - /** - * Handle issue assignee change - * - * @access public - * @param array $issue Issue data - * @return boolean - */ - public function handleIssueAssigned(array $issue) - { - $user = $this->user->getByUsername($issue['assignee']['login']); - $task = $this->taskFinder->getByReference($issue['number']); - - if ($user && $task) { - - $event = array( - 'project_id' => $this->project_id, - 'task_id' => $task['id'], - 'owner_id' => $user['id'], - 'reference' => $issue['number'], - ); - - $this->container['dispatcher']->dispatch( - self::EVENT_ISSUE_ASSIGNEE_CHANGE, - new GenericEvent($event) - ); - - return true; - } - - return false; - } - - /** - * Handle unassigned issue - * - * @access public - * @param array $issue Issue data - * @return boolean - */ - public function handleIssueUnassigned(array $issue) - { - $task = $this->taskFinder->getByReference($issue['number']); - - if ($task) { - - $event = array( - 'project_id' => $this->project_id, - 'task_id' => $task['id'], - 'owner_id' => 0, - 'reference' => $issue['number'], - ); - - $this->container['dispatcher']->dispatch( - self::EVENT_ISSUE_ASSIGNEE_CHANGE, - new GenericEvent($event) - ); - - return true; - } - - return false; - } - - /** - * Handle labeled issue - * - * @access public - * @param array $issue Issue data - * @param array $label Label data - * @return boolean - */ - public function handleIssueLabeled(array $issue, array $label) - { - $task = $this->taskFinder->getByReference($issue['number']); - - if ($task) { - - $event = array( - 'project_id' => $this->project_id, - 'task_id' => $task['id'], - 'reference' => $issue['number'], - 'label' => $label['name'], - ); - - $this->container['dispatcher']->dispatch( - self::EVENT_ISSUE_LABEL_CHANGE, - new GenericEvent($event) - ); - - return true; - } - - return false; - } - - /** - * Handle unlabeled issue - * - * @access public - * @param array $issue Issue data - * @param array $label Label data - * @return boolean - */ - public function handleIssueUnlabeled(array $issue, array $label) - { - $task = $this->taskFinder->getByReference($issue['number']); - - if ($task) { - - $event = array( - 'project_id' => $this->project_id, - 'task_id' => $task['id'], - 'reference' => $issue['number'], - 'label' => $label['name'], - 'category_id' => 0, - ); - - $this->container['dispatcher']->dispatch( - self::EVENT_ISSUE_LABEL_CHANGE, - new GenericEvent($event) - ); - - return true; - } - - return false; - } -} -- cgit v1.2.3