Skip to content
This repository has been archived by the owner on Apr 5, 2020. It is now read-only.

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fguillot committed Nov 22, 2015
0 parents commit c6a5552
Show file tree
Hide file tree
Showing 29 changed files with 384 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Frédéric Guillot

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
7 changes: 7 additions & 0 deletions Locale/cs_CZ/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
'Help on Mattermost integration' => 'Nápověda pro Mattermost integraci.',
'Channel/Group/User (Optional)' => 'Kanál/Skupina/Uživatel (volitelně)',
);

7 changes: 7 additions & 0 deletions Locale/da_DK/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
// 'Help on Mattermost integration' => '',
// 'Channel/Group/User (Optional)' => '',
);

7 changes: 7 additions & 0 deletions Locale/de_DE/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
'Help on Mattermost integration' => 'Hilfe für Mattermost-Integration.',
'Channel/Group/User (Optional)' => 'Kanal/Gruppe/Benutzer (optional)',
);

7 changes: 7 additions & 0 deletions Locale/es_ES/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
'Help on Mattermost integration' => 'Ayuda sobre integración Desatendida',
'Channel/Group/User (Optional)' => 'Canal/Grupo/Usuario (Opcional)',
);

7 changes: 7 additions & 0 deletions Locale/fi_FI/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
// 'Help on Mattermost integration' => '',
// 'Channel/Group/User (Optional)' => '',
);

7 changes: 7 additions & 0 deletions Locale/fr_FR/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
'Help on Mattermost integration' => 'Aide sur l\'intégration avec Mattermost',
'Channel/Group/User (Optional)' => 'Canal/Groupe/Utilisateur (Optionnel)',
);

7 changes: 7 additions & 0 deletions Locale/hu_HU/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
// 'Help on Mattermost integration' => '',
// 'Channel/Group/User (Optional)' => '',
);

7 changes: 7 additions & 0 deletions Locale/id_ID/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
'Help on Mattermost integration' => 'Bantuan pada integrasi Mattermost',
'Channel/Group/User (Optional)' => 'Kanal/Grup/Pengguna (pilihan)',
);

7 changes: 7 additions & 0 deletions Locale/it_IT/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
'Help on Mattermost integration' => 'Guida all\'integrazione con Mattermost',
// 'Channel/Group/User (Optional)' => '',
);

7 changes: 7 additions & 0 deletions Locale/ja_JP/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
'Help on Mattermost integration' => 'Mattermost 連携のヘルプ',
// 'Channel/Group/User (Optional)' => '',
);

7 changes: 7 additions & 0 deletions Locale/nb_NO/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
// 'Help on Mattermost integration' => '',
// 'Channel/Group/User (Optional)' => '',
);

7 changes: 7 additions & 0 deletions Locale/nl_NL/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
// 'Help on Mattermost integration' => '',
// 'Channel/Group/User (Optional)' => '',
);

7 changes: 7 additions & 0 deletions Locale/pl_PL/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
// 'Help on Mattermost integration' => '',
// 'Channel/Group/User (Optional)' => '',
);

7 changes: 7 additions & 0 deletions Locale/pt_BR/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
'Help on Mattermost integration' => 'Ajuda sobre integração com o Mattermost',
'Channel/Group/User (Optional)' => 'Canal/Grupo/Utilizador (Opcional)',
);

7 changes: 7 additions & 0 deletions Locale/pt_PT/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
'Help on Mattermost integration' => 'Ajuda na integração com o Mattermost',
'Channel/Group/User (Optional)' => 'Canal/Grupo/Utilizador (Opcional)',
);

7 changes: 7 additions & 0 deletions Locale/ru_RU/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
'Help on Mattermost integration' => 'Помощь по интеграции Mattermost',
'Channel/Group/User (Optional)' => 'Канал/Группа/Пользователь (опционально)',
);

7 changes: 7 additions & 0 deletions Locale/sr_Latn_RS/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
// 'Help on Mattermost integration' => '',
// 'Channel/Group/User (Optional)' => '',
);

7 changes: 7 additions & 0 deletions Locale/sv_SE/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
'Help on Mattermost integration' => 'Hjälp för Mattermost integration',
'Channel/Group/User (Optional)' => 'Kanal/Grupp/Användare (valfri)',
);

7 changes: 7 additions & 0 deletions Locale/th_TH/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
// 'Help on Mattermost integration' => '',
// 'Channel/Group/User (Optional)' => '',
);

7 changes: 7 additions & 0 deletions Locale/tr_TR/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
// 'Help on Mattermost integration' => '',
// 'Channel/Group/User (Optional)' => '',
);

7 changes: 7 additions & 0 deletions Locale/zh_CN/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return array(
'Help on Mattermost integration' => 'Mattermost 整合帮助',
// 'Channel/Group/User (Optional)' => '',
);

3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
all:
@ echo "Build archive for plugin ${plugin} version=${version}"
@ git archive HEAD --prefix=${plugin}/ --format=zip -o ${plugin}-${version}.zip
101 changes: 101 additions & 0 deletions Notification/Mattermost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

namespace Kanboard\Plugin\Mattermost\Notification;

use Kanboard\Core\Base;
use Kanboard\Notification\NotificationInterface;

/**
* Mattermost Notification
*
* @package notification
* @author Frederic Guillot
*/
class Mattermost extends Base implements NotificationInterface
{
/**
* Send notification to a user
*
* @access public
* @param array $user
* @param string $event_name
* @param array $event_data
*/
public function notifyUser(array $user, $event_name, array $event_data)
{
}

/**
* Send notification to a project
*
* @access public
* @param array $project
* @param string $event_name
* @param array $event_data
*/
public function notifyProject(array $project, $event_name, array $event_data)
{
$webhook = $this->projectMetadata->get($project['id'], 'mattermost_webhook_url', $this->config->get('mattermost_webhook_url'));
$channel = $this->projectMetadata->get($project['id'], 'mattermost_webhook_channel');

if (! empty($webhook)) {
$this->sendMessage($webhook, $channel, $project, $event_name, $event_data);
}
}

/**
* Get message to send
*
* @access public
* @param array $project
* @param string $event_name
* @param array $event_data
*/
public function getMessage(array $project, $event_name, array $event_data)
{
if ($this->userSession->isLogged()) {
$author = $this->helper->user->getFullname();
$title = $this->notification->getTitleWithAuthor($author, $event_name, $event_data);
} else {
$title = $this->notification->getTitleWithoutAuthor($event_name, $event_data);
}

$message = '**['.$project['name']."]** ";
$message .= '_'.$event_data['task']['title']."_\n";
$message .= $title."\n";

if ($this->config->get('application_url') !== '') {
$message .= '['.t('View the task on Kanboard').']';
$message .= '(';
$message .= $this->helper->url->to('task', 'show', array('task_id' => $event_data['task']['id'], 'project_id' => $project['id']), '', true);
$message .= ')';
}

return array(
'text' => $message,
'username' => 'Kanboard',
'icon_url' => 'http://kanboard.net/assets/img/favicon.png',
);
}

/**
* Send message to Mattermost
*
* @access private
* @param srting $webhook
* @param string $channel
* @param array $project
* @param string $event_name
* @param array $event_data
*/
private function sendMessage($webhook, $channel, array $project, $event_name, array $event_data)
{
$payload = $this->getMessage($project, $event_name, $event_data);

if (! empty($channel)) {
$payload['channel'] = $channel;
}

$this->httpClient->postJson($webhook, $payload);
}
}
47 changes: 47 additions & 0 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Kanboard\Plugin\Mattermost;

use Kanboard\Core\Translator;
use Kanboard\Core\Plugin\Base;

/**
* Mattermost Plugin
*
* @package mattermost
* @author Frederic Guillot
*/
class Plugin extends Base
{
public function initialize()
{
$this->template->hook->attach('template:config:integrations', 'mattermost:config/integration');
$this->template->hook->attach('template:project:integrations', 'mattermost:project/integration');

$this->projectNotificationType->setType('mattermost', t('Mattermost'), '\Kanboard\Plugin\Mattermost\Notification\Mattermost');

$this->on('session.bootstrap', function($container) {
Translator::load($container['config']->getCurrentLanguage(), __DIR__.'/Locale');
});
}

public function getPluginDescription()
{
return 'Receive notifications on Mattermost';
}

public function getPluginAuthor()
{
return 'Frédéric Guillot';
}

public function getPluginVersion()
{
return '1.0.0';
}

public function getPluginHomepage()
{
return 'https://github.com/kanboard/plugin-mattermost';
}
}
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Mattermost plugin for Kanboard
==============================

Receive Kanboard notifications on Mattermost.

Author
------

- Frederic Guillot
- License MIT

Installation
------------

- Create a folder **plugins/Mattermost** or uncompress the latest archive in the folder **plugins**
- Copy all files under this directory

Configuration
-------------

Firstly, you have to generate a new webhook url in Mattermost (**Integration Settings > Incoming Webhooks**).

### Receive project notifications to a room

- Go to the project settings then choose **Integrations > Mattermost**
- Copy and paste the webhook url from Mattermost or leave it blank if you want to use the global webhook url
- Use `channel` to override the webhook channel, example: **off-topic**
- Enable Mattermost in your project notifications **Notifications > Mattermost**

You can also define the webhook URL globally in the **Application settings > Integrations > Mattermost**.

### Mattermost configuration

- Change the config option `EnablePostUsernameOverride` to `true` to have Kanboard as username
- Change `EnablePostIconOverride` to `true` to see Kanboard icon

## Troubleshooting

- Enable the debug mode
- All connection errors with the Mattermost API are recorded in the log files `data/debug.log`
11 changes: 11 additions & 0 deletions Template/config/integration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h3><img src="<?= $this->url->dir() ?>plugins/Mattermost/mattermost-icon.png"/>&nbsp;Mattermost</h3>
<div class="listing">
<?= $this->form->label(t('Webhook URL'), 'mattermost_webhook_url') ?>
<?= $this->form->text('mattermost_webhook_url', $values) ?>

<p class="form-help"><a href="https://github.com/kanboard/plugin-mattermost" target="_blank"><?= t('Help on Mattermost integration') ?></a></p>

<div class="form-actions">
<input type="submit" value="<?= t('Save') ?>" class="btn btn-blue"/>
</div>
</div>
Loading

0 comments on commit c6a5552

Please sign in to comment.