Add Slack and Hipchat integrations for each projects

This commit is contained in:
Frederic Guillot
2015-04-18 18:44:45 -04:00
parent f53bb88d10
commit 370b5a0fd7
15 changed files with 368 additions and 81 deletions

View File

@@ -3,7 +3,7 @@
namespace Integration;
/**
* Hipchat Webhook
* Hipchat
*
* @package integration
* @author Frederic Guillot
@@ -11,7 +11,45 @@ namespace Integration;
class Hipchat extends Base
{
/**
* Send message to the Hipchat room
* Return true if Hipchat is enabled for this project or globally
*
* @access public
* @param integer $project_id
* @return boolean
*/
public function isActivated($project_id)
{
return $this->config->get('integration_hipchat') == 1 || $this->projectIntegration->hasValue($project_id, 'hipchat', 1);
}
/**
* Get API parameters
*
* @access public
* @param integer $project_id
* @return array
*/
public function getParameters($project_id)
{
if ($this->config->get('integration_hipchat') == 1) {
return array(
'api_url' => $this->config->get('integration_hipchat_api_url'),
'room_id' => $this->config->get('integration_hipchat_room_id'),
'room_token' => $this->config->get('integration_hipchat_room_token'),
);
}
$options = $this->projectIntegration->getParameters($project_id);
return array(
'api_url' => $options['hipchat_api_url'],
'room_id' => $options['hipchat_room_id'],
'room_token' => $options['hipchat_room_token'],
);
}
/**
* Send the notification if activated
*
* @access public
* @param integer $project_id Project id
@@ -21,33 +59,37 @@ class Hipchat extends Base
*/
public function notify($project_id, $task_id, $event_name, array $event)
{
$project = $this->project->getbyId($project_id);
if ($this->isActivated($project_id)) {
$event['event_name'] = $event_name;
$event['author'] = $this->user->getFullname($this->session['user']);
$params = $this->getParameters($project_id);
$project = $this->project->getbyId($project_id);
$html = '<img src="http://kanboard.net/assets/img/favicon-32x32.png"/>';
$html .= '<strong>'.$project['name'].'</strong><br/>';
$html .= $this->projectActivity->getTitle($event);
$event['event_name'] = $event_name;
$event['author'] = $this->user->getFullname($this->session['user']);
if ($this->config->get('application_url')) {
$html .= '<br/><a href="'.$this->config->get('application_url');
$html .= $this->helper->u('task', 'show', array('task_id' => $task_id, 'project_id' => $project_id)).'">';
$html .= t('view the task on Kanboard').'</a>';
$html = '<img src="http://kanboard.net/assets/img/favicon-32x32.png"/>';
$html .= '<strong>'.$project['name'].'</strong>'.(isset($event['task']['title']) ? '<br/>'.$event['task']['title'] : '').'<br/>';
$html .= $this->projectActivity->getTitle($event);
if ($this->config->get('application_url')) {
$html .= '<br/><a href="'.$this->config->get('application_url');
$html .= $this->helper->u('task', 'show', array('task_id' => $task_id, 'project_id' => $project_id)).'">';
$html .= t('view the task on Kanboard').'</a>';
}
$payload = array(
'message' => $html,
'color' => 'yellow',
);
$url = sprintf(
'%s/v2/room/%s/notification?auth_token=%s',
$params['api_url'],
$params['room_id'],
$params['room_token']
);
$this->httpClient->post($url, $payload);
}
$payload = array(
'message' => $html,
'color' => 'yellow',
);
$url = sprintf(
'%s/v2/room/%s/notification?auth_token=%s',
$this->config->get('integration_hipchat_api_url'),
$this->config->get('integration_hipchat_room_id'),
$this->config->get('integration_hipchat_room_token')
);
$this->httpClient->post($url, $payload);
}
}