Skip to content

Commit

Permalink
Added new plugin to library and some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Klimchuk committed Sep 24, 2015
1 parent b36d1aa commit aea5d15
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 4 deletions.
2 changes: 1 addition & 1 deletion _build/build.transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

define('PKG_NAME', 'Slackify');
define('PKG_NAME_LOWER', strtolower(PKG_NAME));
define('PKG_VERSION', '0.5.0');
define('PKG_VERSION', '0.6.2');
define('PKG_RELEASE', 'beta');

require_once 'xpdo/xpdo/xpdo.class.php';
Expand Down
8 changes: 7 additions & 1 deletion _build/data/transport.plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@

$list = [
'PageNotFoundSlackify' => [
'description' => 'This plugin sends message to defined channel in Slack when 404 error occurs on site.',
'description' => 'This plugin sends messages to defined channel in Slack when 404 error occurs on site.',
'events' => [
'OnPageNotFound'
]
],
'NewCommentTicketsSlackify' => [
'description' => 'This plugin sends messages to defined channel in Slack when somebody add new comment to a ticket.',
'events' => [
'OnCommentSave'
]
]
];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 Ivan Klimchuk
*
* 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.
*/

switch ($modx->event->name) {
case 'OnCommentSave':

$slackify = $modx->getService('slackify');

/** @var TicketComment $comment */
$comment =& $object;

/** @var TicketThread $ticket */
$thread = $comment->getOne('Thread');

/** @var Ticket $ticket */
$ticket = $thread->getOne('Ticket');

$a = new Attachment();
$a->setPretext('Somebody left mention to the important theme on site');

$a->setColor(new Color('#00FF00')); // green
$a->setAuthor(new Author($comment->get('name'), 'mailto:' . $comment->get('email')));

$a->setTitle(new Title("left comment to ticket '{$ticket->get('pagetitle')}'"));
$a->setText($comment->get('text')); // raw

$a->addField(new Field('When', $comment->get('createdon'), true));
$a->addField(new Field('Published', $comment->get('published') ? 'True' : 'False', true));
$a->addField(new Field('Ticket', new Link($modx->makeUrl($ticket->get('id'), 'web', '', 'full'), $ticket->get('pagetitle'))));

$message = new Message('*New comment*');
$message->attach($a);

$slackify->send($message);
break;
}
4 changes: 2 additions & 2 deletions core/components/slackify/model/slackify/Attachment/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function equalsTo(Field $that)
public function jsonSerialize()
{
return [
'title' => $this->title,
'value' => $this->value,
'title' => (string) $this->title,
'value' => (string) $this->value,
'short' => (boolean) $this->short
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,24 @@
* SOFTWARE.
*/

class Link
{
protected $url;
protected $title = '';

public function __construct($url, $title = '')
{
$this->url = $url;
$this->title = $title;
}

public function __toString()
{
$link = $this->url;
if ($this->title) {
$link .= '|' . $this->title;
}

return str_replace('{link}', $link, '<{link}>');
}
}
1 change: 1 addition & 0 deletions core/components/slackify/model/slackify/Slackify.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
include_once 'Attachment/Color.php';
include_once 'Attachment/Field.php';
include_once 'Attachment/Title.php';
include_once 'Attachment/Link.php';
include_once 'Attachment.php';
include_once 'Message.php';

Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
This file shows the changes in recent releases of Slackify.

Slackify 0.6.2-beta (September 24, 2015)
========================================
- Added class Link for generates valid links for Slack
- Added plugin NewCommentTicketsSlackify for send notifies when new comments added

Slackify 0.5.0-beta (September 23, 2015)
========================================
- Added plugin for notify to Slack when 404 error happens

Slackify 0.4.10-alpha (September 23, 2015)
Expand Down

0 comments on commit aea5d15

Please sign in to comment.