Add Hipchat integration

This commit is contained in:
Frederic Guillot 2015-03-29 13:51:51 -04:00
parent 5536f6c6ce
commit 7cbae61dbd
32 changed files with 250 additions and 17 deletions

View File

@ -97,6 +97,7 @@ Documentation
- [Bitbucket webhooks](docs/bitbucket-webhooks.markdown)
- [Github webhooks](docs/github-webhooks.markdown)
- [Gitlab webhooks](docs/gitlab-webhooks.markdown)
- [Hipchat](docs/hipchat.markdown)
- [Slack](docs/slack.markdown)
#### More

View File

@ -44,7 +44,7 @@ class Config extends Base
$values += array('subtask_restriction' => 0, 'subtask_time_tracking' => 0, 'subtask_forecast' => 0);
}
else if ($redirect === 'integrations') {
$values += array('integration_slack_webhook' => 0);
$values += array('integration_slack_webhook' => 0, 'integration_hipchat' => 0);
}
if ($this->config->save($values)) {

View File

@ -47,8 +47,9 @@ class HttpClient
}
$headers = array(
'Connection: close',
'User-Agent: '.self::HTTP_USER_AGENT,
'Content-Type: application/json',
'Connection: close',
);
$context = stream_context_create(array(

View File

@ -0,0 +1,53 @@
<?php
namespace Integration;
/**
* Hipchat Webhook
*
* @package integration
* @author Frederic Guillot
*/
class Hipchat extends Base
{
/**
* Send message to the Hipchat room
*
* @access public
* @param integer $project_id Project id
* @param integer $task_id Task id
* @param string $event_name Event name
* @param array $data Event data
*/
public function notify($project_id, $task_id, $event_name, array $event)
{
$project = $this->project->getbyId($project_id);
$event['event_name'] = $event_name;
$event['author'] = $this->user->getFullname($this->session['user']);
$html = '<img src="http://kanboard.net/assets/img/favicon-32x32.png"/>';
$html .= '<strong>'.$project['name'].'</strong><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',
$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);
}
}

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -825,8 +825,13 @@ return array(
'Reference currency' => 'Devise de référence',
'The currency rate have been added successfully.' => 'Le taux de change a été ajouté avec succès.',
'Unable to add this currency rate.' => 'Impossible d\'ajouter ce taux de change',
'Send notifications to a Slack channel' => 'Envoyer des notifications sur un channel Slack',
'Send notifications to a Slack channel' => 'Envoyer les notifications sur un salon de discussion Slack',
'Webhook URL' => 'URL du webhook',
'Help on Slack integration' => 'Aide sur l\'intégration avec Slack',
'%s remove the assignee of the task %s' => '%s a enlevé la personne assignée à la tâche %s',
'Send notifications to Hipchat' => 'Envoyer les notifications vers Hipchat',
'API URL' => 'URL de l\'api',
'Room API ID or name' => 'Nom ou identifiant du salon de discussion',
'Room notification token' => 'Jeton de sécurité du salon de discussion',
'Help on Hipchat integration' => 'Aide sur l\'intégration avec Hipchat',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -827,4 +827,9 @@ return array(
// 'Webhook URL' => '',
// 'Help on Slack integration' => '',
// '%s remove the assignee of the task %s' => '',
// 'Send notifications to Hipchat' => '',
// 'API URL' => '',
// 'Room API ID or name' => '',
// 'Room notification token' => '',
// 'Help on Hipchat integration' => '',
);

View File

@ -6,7 +6,16 @@ use PDO;
use Core\Security;
use Model\Link;
const VERSION = 58;
const VERSION = 59;
function version_59($pdo)
{
$rq = $pdo->prepare('INSERT INTO settings VALUES (?, ?)');
$rq->execute(array('integration_hipchat', '0'));
$rq->execute(array('integration_hipchat_api_url', 'https://api.hipchat.com'));
$rq->execute(array('integration_hipchat_room_id', ''));
$rq->execute(array('integration_hipchat_room_token', ''));
}
function version_58($pdo)
{

View File

@ -6,7 +6,16 @@ use PDO;
use Core\Security;
use Model\Link;
const VERSION = 39;
const VERSION = 40;
function version_40($pdo)
{
$rq = $pdo->prepare('INSERT INTO settings VALUES (?, ?)');
$rq->execute(array('integration_hipchat', '0'));
$rq->execute(array('integration_hipchat_api_url', 'https://api.hipchat.com'));
$rq->execute(array('integration_hipchat_room_id', ''));
$rq->execute(array('integration_hipchat_room_token', ''));
}
function version_39($pdo)
{

View File

@ -6,7 +6,16 @@ use Core\Security;
use PDO;
use Model\Link;
const VERSION = 57;
const VERSION = 58;
function version_58($pdo)
{
$rq = $pdo->prepare('INSERT INTO settings VALUES (?, ?)');
$rq->execute(array('integration_hipchat', '0'));
$rq->execute(array('integration_hipchat_api_url', 'https://api.hipchat.com'));
$rq->execute(array('integration_hipchat_room_id', ''));
$rq->execute(array('integration_hipchat_room_token', ''));
}
function version_57($pdo)
{

View File

@ -75,6 +75,7 @@ class ClassProvider implements ServiceProviderInterface
'GitlabWebhook',
'GithubWebhook',
'BitbucketWebhook',
'Hipchat',
'SlackWebhook',
)
);

View File

@ -42,14 +42,32 @@ class ProjectActivitySubscriber extends Base implements EventSubscriberInterface
$values
);
if ($this->config->get('integration_slack_webhook') == 1) {
$this->slackWebhook->notify(
$values['task']['project_id'],
$values['task']['id'],
$event_name,
$values
);
}
$this->sendSlackNotification($event_name, $values);
$this->sendHipchatNotification($event_name, $values);
}
}
private function sendSlackNotification($event_name, array $values)
{
if ($this->config->get('integration_slack_webhook') == 1) {
$this->slackWebhook->notify(
$values['task']['project_id'],
$values['task']['id'],
$event_name,
$values
);
}
}
private function sendHipchatNotification($event_name, array $values)
{
if ($this->config->get('integration_hipchat') == 1) {
$this->hipchat->notify(
$values['task']['project_id'],
$values['task']['id'],
$event_name,
$values
);
}
}

View File

@ -6,6 +6,22 @@
<?= $this->formCsrf() ?>
<h3><img src="assets/img/hipchat-icon.png"/> <?= t('Hipchat') ?></h3>
<div class="listing">
<?= $this->formCheckbox('integration_hipchat', t('Send notifications to Hipchat'), 1, $values['integration_hipchat'] == 1) ?>
<?= $this->formLabel(t('API URL'), 'integration_hipchat_api_url') ?>
<?= $this->formText('integration_hipchat_api_url', $values, $errors) ?>
<?= $this->formLabel(t('Room API ID or name'), 'integration_hipchat_room_id') ?>
<?= $this->formText('integration_hipchat_room_id', $values, $errors) ?>
<?= $this->formLabel(t('Room notification token'), 'integration_hipchat_room_token') ?>
<?= $this->formText('integration_hipchat_room_token', $values, $errors) ?>
<p class="form-help"><a href="http://kanboard.net/documentation/hipchat" target="_blank"><?= t('Help on Hipchat integration') ?></a></p>
</div>
<h3><i class="fa fa-slack fa-fw"></i>&nbsp;<?= t('Slack') ?></h3>
<div class="listing">
<?= $this->formCheckbox('integration_slack_webhook', t('Send notifications to a Slack channel'), 1, $values['integration_slack_webhook'] == 1) ?>

View File

@ -8,7 +8,7 @@
<p class="form-help"><a href="http://kanboard.net/documentation/github-webhooks" target="_blank"><?= t('Help on Github webhooks') ?></a></p>
</div>
<h3><i class="fa fa-git fa-fw"></i>&nbsp;<?= t('Gitlab webhooks') ?></h3>
<h3><img src="assets/img/gitlab-icon.png"/>&nbsp;<?= t('Gitlab webhooks') ?></h3>
<div class="listing">
<input type="text" class="auto-select" readonly="readonly" value="<?= $this->getCurrentBaseUrl().$this->u('webhook', 'gitlab', array('token' => $webhook_token, 'project_id' => $project['id'])) ?>"/><br/>
<p class="form-help"><a href="http://kanboard.net/documentation/gitlab-webhooks" target="_blank"><?= t('Help on Gitlab webhooks') ?></a></p>

BIN
assets/img/gitlab-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 661 B

BIN
assets/img/hipchat-icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

31
docs/hipchat.markdown Normal file
View File

@ -0,0 +1,31 @@
Hipchat integration
===================
Send notifications to a room
-----------------------------
Example of notifications:
![Hipchat notification](http://kanboard.net/screenshots/documentation/hipchat-notification.png)
This feature use the room notification token system of Hipchat.
### Hipchat configuration
![Hipchat room token](http://kanboard.net/screenshots/documentation/hipchat-room-token.png)
1. Go to to **My account**
2. Click on the tab **Rooms** and select the room you want to send the notifications
3. On the left, choose **Tokens**
4. Enter a label, by example "Kanboard" and save
### Kanboard configuration
![Hipchat settings](http://kanboard.net/screenshots/documentation/hipchat-settings.png)
1. Go to **Settings > Integrations > Hipchat**
2. Replace the API url if you use the self-hosted version of Hipchat
3. Set the room name or the room API ID
4. Copy and paste the token generated previously
Now, all Kanboard events will be sent to the Hipchat room.

View File

@ -10,7 +10,7 @@ Example of notifications:
This feature use the [Incoming webhook](https://api.slack.com/incoming-webhooks) system of Slack.
### Configure Slack
### Slack configuration
![Slack webhook creation](http://kanboard.net/screenshots/documentation/slack-add-incoming-webhook.png)
@ -18,4 +18,4 @@ This feature use the [Incoming webhook](https://api.slack.com/incoming-webhooks)
2. On the list of services, scroll-down and choose **DIY Integrations & Customizations > Incoming WebHooks**
3. Copy the webhook url to the Kanboard settings page: **Settings > Integrations > Slack**
Now, all Kanboard events will be sent to the Slack channel.