Commit 68cb119d authored by ManiacTwister's avatar ManiacTwister
Browse files

Added colors

parent 89a86388
SECRET="yourverysecretkey"
DEFAULT_CHANNEL="ircs://irc.example.tld/#channel"
IRKER_HOST="localhost"
IRKER_PORT="6659"
COLORS=1
......@@ -3,14 +3,17 @@ namespace ManiacTwister\Irker\Messages;
use ManiacTwister\Irker\Messages\Traits\ExtractProjectName;
use ManiacTwister\Irker\Messages\Traits\GetShortSha;
use ManiacTwister\Irker\Messages\Traits\Colors;
class BuildMessage implements IrkerMessage
{
use ExtractProjectName;
use GetShortSha;
use Colors;
public function __construct($data)
public function __construct($data, $colors=false)
{
$this->colors = $colors;
if(($this->project = $this->extractProjectName($data->repository->url)) == false)
{
$this->project = $data->repository->name;
......@@ -37,13 +40,13 @@ class BuildMessage implements IrkerMessage
return false;
return sprintf("[%s] Build of commit %s from %s %s in %s seconds\n Commit: %s\n Build: %s",
$this->project,
$this->sha,
$this->colorProject($this->project, $this->colors),
$this->colorSha($this->sha, $this->colors),
$this->username,
$this->status,
$this->duration,
$this->commitlink,
$this->buildlink
$this->colorStatus($this->status, $this->colors),
$this->colorNumber($this->duration, $this->colors),
$this->colorLink($this->commitlink, $this->colors),
$this->colorLink($this->buildlink, $this->colors)
);
}
}
......@@ -3,5 +3,6 @@ namespace ManiacTwister\Irker\Messages;
interface IrkerMessage
{
public function __construct($data, $color=false);
public function getMessage();
}
......@@ -3,14 +3,17 @@ namespace ManiacTwister\Irker\Messages;
use ManiacTwister\Irker\Messages\Traits\ExtractProjectName;
use ManiacTwister\Irker\Messages\Traits\GetAdjective;
use ManiacTwister\Irker\Messages\Traits\Colors;
class IssueMessage implements IrkerMessage
{
use ExtractProjectName;
use GetAdjective;
use Colors;
public function __construct($data)
public function __construct($data, $colors=false)
{
$this->colors = $colors;
if(($this->project = $this->extractProjectName($data->repository->url)) == false)
{
$this->project = $data->repository->name;
......@@ -28,12 +31,12 @@ class IssueMessage implements IrkerMessage
public function getMessage()
{
return sprintf('[%s] %s %s issue #%d: %s - %s',
$this->project,
$this->colorProject($this->project, $this->colors),
$this->username,
$this->action,
$this->issueid,
$this->title,
$this->link
$this->colorLink($this->link, $this->colors)
);
}
}
......@@ -3,14 +3,17 @@ namespace ManiacTwister\Irker\Messages;
use ManiacTwister\Irker\Messages\Traits\ExtractProjectName;
use ManiacTwister\Irker\Messages\Traits\GetAdjective;
use ManiacTwister\Irker\Messages\Traits\Colors;
class MergeMessage implements IrkerMessage
{
use ExtractProjectName;
use GetAdjective;
use Colors;
public function __construct($data)
public function __construct($data, $colors=false)
{
$this->colors = $colors;
if(($this->project = $this->extractProjectName($data->repository->url)) == false)
{
$this->project = $data->repository->name;
......@@ -28,12 +31,12 @@ class MergeMessage implements IrkerMessage
public function getMessage()
{
return sprintf('[%s] %s %s merge request #%d: %s - %s',
$this->project,
$this->colorProject($this->project, $this->colors),
$this->username,
$this->action,
$this->mergeid,
$this->title,
$this->link
$this->colorLink($this->link, $this->colors)
);
}
}
......@@ -3,16 +3,19 @@ namespace ManiacTwister\Irker\Messages;
use ManiacTwister\Irker\Messages\Traits\ExtractProjectName;
use ManiacTwister\Irker\Messages\Traits\GetShortSha;
use ManiacTwister\Irker\Messages\Traits\Colors;
class NoteMessage implements IrkerMessage
{
use ExtractProjectName;
use GetShortSha;
use Colors;
private $message = false;
public function __construct($data)
public function __construct($data, $colors=false)
{
$this->colors = $colors;
if(($this->project = $this->extractProjectName($data->repository->url)) == false)
{
$this->project = $data->repository->name;
......@@ -45,18 +48,19 @@ class NoteMessage implements IrkerMessage
private function note($target, $title)
{
return sprintf('[%s] %s commented on %s: %s - %s',
$this->project,
$this->colorProject($this->project, $this->colors),
$this->username,
$target,
$this->title($title),
$this->noteurl
$this->colorLink($this->noteurl, $this->colors)
);
}
private function commit($data)
{
// Get short sha. We don't care for sha collisions here ...
$sha = $this->getShortSha($data->id);
$sha = $this->colorSha($sha, $this->colors);
$target = 'commit '.$sha;
return $this->note($target, $data->title);
......
<?php
namespace ManiacTwister\Irker\Messages\Traits;
trait Colors
{
public function colorProject($project, $colors)
{
return ($colors ? "\x0304".$project."\x0f" : $project);
}
public function colorSha($sha, $colors)
{
return ($colors ? "\x0314".$sha."\x0f" : $sha);
}
public function colorLink($link, $colors)
{
return ($colors ? "\x0302".$link."\x0f" : $link);
}
public function colorNumber($num, $colors)
{
return ($colors ? "\x0312".$num."\x0f" : $num);
}
public function colorStatus($status, $colors)
{
if(!$colors)
return $status;
if($status == 'succeeded')
return "\x0303".$status."\x0f";
return "\x0305".$status."\x0f";
}
}
......@@ -37,6 +37,17 @@ else
die('No channel provided');
}
}
if(array_key_exists('colors', $_GET))
{
$colors = ($_GET['colors'] == 'true' ? true : false);
}
else
{
if(($colors = getenv('COLORS')) === false)
{
$colors = false;
}
}
$input = file_get_contents("php://input");
$json = json_decode($input);
......@@ -50,16 +61,16 @@ $message = false;
switch($json->object_kind)
{
case 'issue':
$message = new Messages\IssueMessage($json);
$message = new Messages\IssueMessage($json, $colors);
break;
case 'note':
$message = new Messages\NoteMessage($json);
$message = new Messages\NoteMessage($json, $colors);
break;
case 'build':
$message = new Messages\BuildMessage($json);
$message = new Messages\BuildMessage($json, $colors);
break;
case 'merge_request':
$message = new Messages\MergeMessage($json);
$message = new Messages\MergeMessage($json, $colors);
break;
}
......
......@@ -17,6 +17,10 @@ if(($channel = getenv('DEFAULT_CHANNEL')) === false)
{
die('No channel provided');
}
if(($colors = getenv('COLORS')) === false)
{
$colors = false;
}
$files = array(
'./payloads/open_issue.json',
......@@ -43,16 +47,16 @@ foreach($files as $file)
switch($json->object_kind)
{
case 'issue':
$message = new Messages\IssueMessage($json);
$message = new Messages\IssueMessage($json, $colors);
break;
case 'note':
$message = new Messages\NoteMessage($json);
$message = new Messages\NoteMessage($json, $colors);
break;
case 'build':
$message = new Messages\BuildMessage($json);
$message = new Messages\BuildMessage($json, $colors);
break;
case 'merge_request':
$message = new Messages\MergeMessage($json);
$message = new Messages\MergeMessage($json, $colors);
break;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment