summaryrefslogtreecommitdiff
path: root/app/Integration
diff options
context:
space:
mode:
Diffstat (limited to 'app/Integration')
-rw-r--r--app/Integration/GitlabWebhook.php67
-rw-r--r--app/Integration/HipchatWebhook.php3
-rw-r--r--app/Integration/Jabber.php3
-rw-r--r--app/Integration/SlackWebhook.php3
4 files changed, 62 insertions, 14 deletions
diff --git a/app/Integration/GitlabWebhook.php b/app/Integration/GitlabWebhook.php
index dce7413a..b8925daf 100644
--- a/app/Integration/GitlabWebhook.php
+++ b/app/Integration/GitlabWebhook.php
@@ -21,14 +21,16 @@ class GitlabWebhook extends \Core\Base
const EVENT_ISSUE_OPENED = 'gitlab.webhook.issue.opened';
const EVENT_ISSUE_CLOSED = 'gitlab.webhook.issue.closed';
const EVENT_COMMIT = 'gitlab.webhook.commit';
+ const EVENT_ISSUE_COMMENT = 'gitlab.webhook.issue.commented';
/**
* Supported webhook events
*
* @var string
*/
- const TYPE_PUSH = 'push';
- const TYPE_ISSUE = 'issue';
+ const TYPE_PUSH = 'push';
+ const TYPE_ISSUE = 'issue';
+ const TYPE_COMMENT = 'comment';
/**
* Project id
@@ -63,6 +65,8 @@ class GitlabWebhook extends \Core\Base
return $this->handlePushEvent($payload);
case self::TYPE_ISSUE;
return $this->handleIssueEvent($payload);
+ case self::TYPE_COMMENT;
+ return $this->handleCommentEvent($payload);
}
return false;
@@ -77,15 +81,20 @@ class GitlabWebhook extends \Core\Base
*/
public function getType(array $payload)
{
- if (isset($payload['object_kind']) && $payload['object_kind'] === 'issue') {
- return self::TYPE_ISSUE;
+ if (empty($payload['object_kind'])) {
+ return '';
}
- if (isset($payload['commits'])) {
- return self::TYPE_PUSH;
+ switch ($payload['object_kind']) {
+ case 'issue':
+ return self::TYPE_ISSUE;
+ case 'note':
+ return self::TYPE_COMMENT;
+ case 'push':
+ return self::TYPE_PUSH;
+ default:
+ return '';
}
-
- return '';
}
/**
@@ -213,4 +222,46 @@ class GitlabWebhook extends \Core\Base
return false;
}
+
+ /**
+ * Parse comment issue events
+ *
+ * @access public
+ * @param array $payload Event data
+ * @return boolean
+ */
+ public function handleCommentEvent(array $payload)
+ {
+ if (! isset($payload['issue'])) {
+ return false;
+ }
+
+ $task = $this->taskFinder->getByReference($this->project_id, $payload['issue']['id']);
+
+ if (! empty($task)) {
+
+ $user = $this->user->getByUsername($payload['user']['username']);
+
+ if (! empty($user) && ! $this->projectPermission->isMember($this->project_id, $user['id'])) {
+ $user = array();
+ }
+
+ $event = array(
+ 'project_id' => $this->project_id,
+ 'reference' => $payload['object_attributes']['id'],
+ 'comment' => $payload['object_attributes']['note']."\n\n[".t('By @%s on Gitlab', $payload['user']['username']).']('.$payload['object_attributes']['url'].')',
+ 'user_id' => ! empty($user) ? $user['id'] : 0,
+ 'task_id' => $task['id'],
+ );
+
+ $this->container['dispatcher']->dispatch(
+ self::EVENT_ISSUE_COMMENT,
+ new GenericEvent($event)
+ );
+
+ return true;
+ }
+
+ return false;
+ }
}
diff --git a/app/Integration/HipchatWebhook.php b/app/Integration/HipchatWebhook.php
index f1be0f34..1d08e514 100644
--- a/app/Integration/HipchatWebhook.php
+++ b/app/Integration/HipchatWebhook.php
@@ -72,8 +72,7 @@ class HipchatWebhook extends \Core\Base
$html .= $this->projectActivity->getTitle($event);
if ($this->config->get('application_url')) {
- $html .= '<br/><a href="'.$this->config->get('application_url');
- $html .= $this->helper->url->href('task', 'show', array('task_id' => $task_id, 'project_id' => $project_id)).'">';
+ $html .= '<br/><a href="'.$this->helper->url->href('task', 'show', array('task_id' => $task_id, 'project_id' => $project_id), false, '', true).'">';
$html .= t('view the task on Kanboard').'</a>';
}
diff --git a/app/Integration/Jabber.php b/app/Integration/Jabber.php
index a1191662..3e403aab 100644
--- a/app/Integration/Jabber.php
+++ b/app/Integration/Jabber.php
@@ -81,8 +81,7 @@ class Jabber extends \Core\Base
$payload = '['.$project['name'].'] '.str_replace('&quot;', '"', $this->projectActivity->getTitle($event)).(isset($event['task']['title']) ? ' ('.$event['task']['title'].')' : '');
if ($this->config->get('application_url')) {
- $payload .= ' '.$this->config->get('application_url');
- $payload .= $this->helper->url->to('task', 'show', array('task_id' => $task_id, 'project_id' => $project_id));
+ $payload .= ' '.$this->helper->url->to('task', 'show', array('task_id' => $task_id, 'project_id' => $project_id), false, '', true);
}
$this->sendMessage($project_id, $payload);
diff --git a/app/Integration/SlackWebhook.php b/app/Integration/SlackWebhook.php
index 498cea09..d238652f 100644
--- a/app/Integration/SlackWebhook.php
+++ b/app/Integration/SlackWebhook.php
@@ -83,8 +83,7 @@ class SlackWebhook extends \Core\Base
);
if ($this->config->get('application_url')) {
- $payload['text'] .= ' - <'.$this->config->get('application_url');
- $payload['text'] .= $this->helper->url->href('task', 'show', array('task_id' => $task_id, 'project_id' => $project_id));
+ $payload['text'] .= ' - <'.$this->helper->url->href('task', 'show', array('task_id' => $task_id, 'project_id' => $project_id), false, '', true);
$payload['text'] .= '|'.t('view the task on Kanboard').'>';
}