Commit 89a86388 authored by ManiacTwister's avatar ManiacTwister
Browse files

Initial commit

parents
SECRET="yourverysecretkey"
DEFAULT_CHANNEL="ircs://irc.example.tld/#channel"
/vendor
composer.phar
composer.lock
.php_cs.cache
.DS_Store
Thumbs.db
.env
<?php
namespace ManiacTwister\Irker\Messages;
use ManiacTwister\Irker\Messages\Traits\ExtractProjectName;
use ManiacTwister\Irker\Messages\Traits\GetShortSha;
class BuildMessage implements IrkerMessage
{
use ExtractProjectName;
use GetShortSha;
public function __construct($data)
{
if(($this->project = $this->extractProjectName($data->repository->url)) == false)
{
$this->project = $data->repository->name;
}
$this->username = $data->commit->author_name;
$this->sha = $this->getShortSha($data->commit->sha);
$this->status = $this->status($data->build_status);
$this->duration = $data->commit->duration;
$this->commitlink = $data->repository->homepage.'/commit/'.$data->commit->sha;
$this->buildlink = $data->repository->homepage.'/builds/'.$data->build_id;
}
private function status($status)
{
if($status == 'success')
return 'succeeded';
return $status;
}
public function getMessage()
{
if($this->status == 'running' || $this->status == 'pending')
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->username,
$this->status,
$this->duration,
$this->commitlink,
$this->buildlink
);
}
}
<?php
namespace ManiacTwister\Irker\Messages;
interface IrkerMessage
{
public function getMessage();
}
<?php
namespace ManiacTwister\Irker\Messages;
use ManiacTwister\Irker\Messages\Traits\ExtractProjectName;
use ManiacTwister\Irker\Messages\Traits\GetAdjective;
class IssueMessage implements IrkerMessage
{
use ExtractProjectName;
use GetAdjective;
public function __construct($data)
{
if(($this->project = $this->extractProjectName($data->repository->url)) == false)
{
$this->project = $data->repository->name;
}
$this->username = $data->user->name;
$attr = $data->object_attributes;
$this->action = $attr->action;
$this->issueid = $attr->iid;
$this->title = $attr->title;
$this->link = $attr->url;
$this->action = $this->getAdjective($this->action);
}
public function getMessage()
{
return sprintf('[%s] %s %s issue #%d: %s - %s',
$this->project,
$this->username,
$this->action,
$this->issueid,
$this->title,
$this->link
);
}
}
<?php
namespace ManiacTwister\Irker\Messages;
use ManiacTwister\Irker\Messages\Traits\ExtractProjectName;
use ManiacTwister\Irker\Messages\Traits\GetAdjective;
class MergeMessage implements IrkerMessage
{
use ExtractProjectName;
use GetAdjective;
public function __construct($data)
{
if(($this->project = $this->extractProjectName($data->repository->url)) == false)
{
$this->project = $data->repository->name;
}
$this->username = $data->user->name;
$attr = $data->object_attributes;
$this->action = $attr->action;
$this->mergeid = $attr->iid;
$this->title = $attr->title;
$this->link = $attr->url;
$this->action = $this->getAdjective($this->action);
}
public function getMessage()
{
return sprintf('[%s] %s %s merge request #%d: %s - %s',
$this->project,
$this->username,
$this->action,
$this->mergeid,
$this->title,
$this->link
);
}
}
<?php
namespace ManiacTwister\Irker\Messages;
use ManiacTwister\Irker\Messages\Traits\ExtractProjectName;
use ManiacTwister\Irker\Messages\Traits\GetShortSha;
class NoteMessage implements IrkerMessage
{
use ExtractProjectName;
use GetShortSha;
private $message = false;
public function __construct($data)
{
if(($this->project = $this->extractProjectName($data->repository->url)) == false)
{
$this->project = $data->repository->name;
}
$this->username = $data->user->name;
$attr = $data->object_attributes;
$this->noteurl = $attr->url;
switch($attr->noteable_type)
{
case 'Commit':
$this->message = $this->commit($data->commit);
break;
case 'Issue':
$this->message = $this->issue($data->issue);
break;
case 'MergeRequest':
$this->message = $this->merge($data->merge_request);
break;
}
}
private function title($title)
{
return strtok($title, "\n");
}
private function note($target, $title)
{
return sprintf('[%s] %s commented on %s: %s - %s',
$this->project,
$this->username,
$target,
$this->title($title),
$this->noteurl
);
}
private function commit($data)
{
// Get short sha. We don't care for sha collisions here ...
$sha = $this->getShortSha($data->id);
$target = 'commit '.$sha;
return $this->note($target, $data->title);
}
private function issue($data)
{
$target = 'issue #'.$data->iid;
return $this->note($target, $data->title);
}
private function merge($data)
{
$target = 'merge request #'.$data->iid;
return $this->note($target, $data->title);
}
public function getMessage()
{
return $this->message;
}
}
<?php
namespace ManiacTwister\Irker\Messages\Traits;
trait ExtractProjectName
{
public function extractProjectName($url)
{
// Extract project name from git url
if(preg_match("/.*@.*:(.*).git$/", $url, $matches)) {
return $matches[1];
}
return false;
}
}
<?php
namespace ManiacTwister\Irker\Messages\Traits;
trait GetAdjective
{
public function getAdjective($action)
{
// Get adjective
if($action == 'close' || $action == 'update' || $action == 'merge')
return $action.'d';
else
return $action.'ed';
}
}
<?php
namespace ManiacTwister\Irker\Messages\Traits;
trait GetShortSha
{
public function getShortSha($sha)
{
// Get short sha. We don't care for sha collisions here ...
return substr($sha, 0, 7);
}
}
# PHP Irker
This is a gitlab webhook to irker relay.
## Supported hooks
* Issue
* Merge requests
* Builds
* Comments
Push events aren't supported because they are supported by the gitlab irker service already.
# Install
```
git clone https://git.s7t.de/ManiacTwister/gitlab-irker.git
cd gitlab-irker
composer install
cp .env.example .env
```
* Configure the values in ```.env```
* Make the public (ONLY the public folder!) folder accessible from a web server
* Add a webhook to your gitlab repository
* http://localhost/url/to/irker.php?secret=yoursecret
* Activate the triggers you want
{
"name": "maniactwister/irker",
"description": "Gitlab to irker bridge",
"version": "0.0.1",
"type": "standalone",
"license": "GPL-3.0+",
"authors": [
{
"name": "ManiacTwister"
}
],
"require": {
"vlucas/phpdotenv": "2.2.*",
"monolog/monolog": "1.17.*"
},
"autoload": {
"psr-4": {
"ManiacTwister\\Irker\\": ""
}
}
}
{"object_kind":"issue","user":{"name":"Administrator","username":"root","avatar_url":"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon"},"repository":{"name":"g","url":"gitlab@localhost:root/g.git","description":"","homepage":"http://localhost:9900/root/g"},"object_attributes":{"id":1,"title":"tztzt","assignee_id":null,"author_id":1,"project_id":1,"created_at":"2016-01-20 01:01:20 UTC","updated_at":"2016-01-20 01:08:45 UTC","position":0,"branch_name":null,"description":"tgtz","milestone_id":null,"state":"opened","iid":1,"updated_by_id":1,"weight":null,"url":"http://localhost:9900/root/g/issues/1","action":"update"}}
{"object_kind":"build","ref":"sni","tag":false,"before_sha":"0000000000000000000000000000000000000000","sha":"3ab0934943404d4191f091a7713ceeeb0c69f501","build_id":2,"build_name":"build","build_stage":"test","build_status":"running","build_started_at":"2016-01-20 21:16:17 UTC","build_finished_at":null,"build_duration":0.091225389,"project_id":77,"project_name":"root / g","user":{"id":null,"name":null,"email":null},"commit":{"id":23,"sha":"3ab0934943404d4191f091a7713ceeeb0c69f501","message":"Added gitlab-ci.yml\n","author_name":"ManiacTwister","author_email":"git@s7t.de","status":"running","duration":0,"started_at":"2016-01-13 14:51:38 UTC","finished_at":"2016-01-13 14:52:22 UTC"},"repository":{"name":"g","url":"git@git.s7t.de:root/g.git","description":"","homepage":"https://git.s7t.de/root/g","git_http_url":"https://git.s7t.de/root/g.git","git_ssh_url":"git@git.s7t.de:root/g.git","visibility_level":0}}
{"object_kind":"build","ref":"sni","tag":false,"before_sha":"0000000000000000000000000000000000000000","sha":"3ab0934943404d4191f091a7713ceeeb0c69f501","build_id":2,"build_name":"build","build_stage":"test","build_status":"success","build_started_at":"2016-01-20 21:16:17 UTC","build_finished_at":"2016-01-20 21:17:00 UTC","build_duration":43.366511954,"project_id":77,"project_name":"root / g","user":{"id":null,"name":null,"email":null},"commit":{"id":23,"sha":"3ab0934943404d4191f091a7713ceeeb0c69f501","message":"Added gitlab-ci.yml\n","author_name":"ManiacTwister","author_email":"git@s7t.de","status":"success","duration":43,"started_at":"2016-01-13 14:51:38 UTC","finished_at":"2016-01-20 21:17:00 UTC"},"repository":{"name":"g","url":"gitlab@localhost:root/g.git","description":"","homepage":"https://localhost/root/g.git","git_http_url":"https://localhost/root/g.git","git_ssh_url":"gitlab@localhost:root/g.git","visibility_level":0}}
{"object_kind":"issue","user":{"name":"Administrator","username":"root","avatar_url":"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon"},"repository":{"name":"g","url":"gitlab@localhost:root/g.git","description":"","homepage":"http://localhost:9900/root/g"},"object_attributes":{"id":2,"title":"fef","assignee_id":null,"author_id":1,"project_id":1,"created_at":"2016-01-20 01:06:55 UTC","updated_at":"2016-01-20 01:07:28 UTC","position":0,"branch_name":null,"description":"fefef","milestone_id":null,"state":"closed","iid":2,"updated_by_id":null,"weight":null,"url":"http://localhost:9900/root/g/issues/2","action":"close"}}
{"object_kind":"note","user":{"name":"Administrator","username":"root","avatar_url":"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon"},"project_id":1,"repository":{"name":"g","url":"gitlab@localhost:root/g.git","description":"","homepage":"http://localhost:9900/root/g"},"object_attributes":{"id":1,"note":"test","noteable_type":"Issue","author_id":1,"created_at":"2016-01-20 01:06:10 UTC","updated_at":"2016-01-20 01:06:10 UTC","project_id":1,"attachment":null,"line_code":null,"commit_id":"","noteable_id":1,"system":false,"st_diff":null,"updated_by_id":null,"is_award":false,"url":"http://localhost:9900/root/g/issues/1#note_1"},"issue":{"id":1,"title":"tztzt","assignee_id":null,"author_id":1,"project_id":1,"created_at":"2016-01-20 01:01:20 UTC","updated_at":"2016-01-20 01:01:20 UTC","position":0,"branch_name":null,"description":"tgtz","milestone_id":null,"state":"opened","iid":1,"updated_by_id":null,"weight":null}}
{"object_kind":"note","user":{"name":"ManiacTwister","username":"ManiacTwister","avatar_url":"https://git.s7t.de/uploads/user/avatar/3/ava1_400x400.png"},"project_id":98,"repository":{"name":"g","url":"git@git.s7t.de:root/g.git","description":"","homepage":"https://git.s7t.de/root/g"},"object_attributes":{"id":73,"note":"test","noteable_type":"MergeRequest","author_id":3,"created_at":"2016-01-20 21:52:36 UTC","updated_at":"2016-01-20 21:52:36 UTC","project_id":98,"attachment":null,"line_code":null,"commit_id":"","noteable_id":7,"st_diff":null,"system":false,"updated_by_id":null,"is_award":false,"url":"https://git.s7t.de/root/g/merge_requests/1#note_73"},"merge_request":{"id":7,"target_branch":"master","source_branch":"test","source_project_id":98,"author_id":3,"assignee_id":null,"title":"test","created_at":"2016-01-20 21:47:23 UTC","updated_at":"2016-01-20 21:47:23 UTC","milestone_id":null,"state":"opened","merge_status":"can_be_merged","target_project_id":98,"iid":1,"description":"testing webhook","position":0,"locked_at":null,"updated_by_id":null,"merge_error":null,"merge_params":{},"merge_when_build_succeeds":false,"merge_user_id":null,"source":{"name":"g","ssh_url":"git@git.s7t.de:root/g.git","http_url":"https://git.s7t.de/root/g.git","web_url":"https://git.s7t.de/root/g","namespace":"ManiacTwister","visibility_level":0},"target":{"name":"g","ssh_url":"git@git.s7t.de:root/g.git","http_url":"https://git.s7t.de/root/g.git","web_url":"https://git.s7t.de/root/g","namespace":"ManiacTwister","visibility_level":0},"last_commit":{"id":"7ed279163735b6215fc30f893b5fba087bfe3079","message":"test","timestamp":"2016-01-20T22:46:50+01:00","url":"https://git.s7t.de/root/g/commit/7ed279163735b6215fc30f893b5fba087bfe3079","author":{"name":"ManiacTwister","email":"git@s7t.de"}},"work_in_progress":false}}
{"object_kind":"merge_request","user":{"name":"ManiacTwister","username":"ManiacTwister","avatar_url":"https://git.s7t.de/uploads/user/avatar/3/ava1_400x400.png"},"repository":{"name":"g","url":"git@git.s7t.de:root/g.git","description":"","homepage":"https://git.s7t.de/root/g"},"object_attributes":{"id":7,"target_branch":"master","source_branch":"test","source_project_id":98,"author_id":3,"assignee_id":null,"title":"test","created_at":"2016-01-20 21:47:23 UTC","updated_at":"2016-01-20 21:54:07 UTC","milestone_id":null,"state":"merged","merge_status":"can_be_merged","target_project_id":98,"iid":1,"description":"testing webhook","position":0,"locked_at":null,"updated_by_id":null,"merge_error":null,"merge_params":{},"merge_when_build_succeeds":false,"merge_user_id":null,"source":{"name":"g","ssh_url":"git@git.s7t.de:root/g.git","http_url":"https://git.s7t.de/root/g.git","web_url":"https://git.s7t.de/root/g","namespace":"ManiacTwister","visibility_level":0},"target":{"name":"g","ssh_url":"git@git.s7t.de:root/g.git","http_url":"https://git.s7t.de/root/g.git","web_url":"https://git.s7t.de/root/g","namespace":"ManiacTwister","visibility_level":0},"last_commit":{"id":"7ed279163735b6215fc30f893b5fba087bfe3079","message":"test","timestamp":"2016-01-20T22:46:50+01:00","url":"https://git.s7t.de/root/g/commit/7ed279163735b6215fc30f893b5fba087bfe3079","author":{"name":"ManiacTwister","email":"git@s7t.de"}},"work_in_progress":false,"url":"https://git.s7t.de/root/g/merge_requests/1","action":"merge"}}
{"object_kind":"merge_request","user":{"name":"ManiacTwister","username":"ManiacTwister","avatar_url":"https://git.s7t.de/uploads/user/avatar/3/ava1_400x400.png"},"repository":{"name":"g","url":"git@git.s7t.de:root/g.git","description":"","homepage":"https://git.s7t.de/root/g"},"object_attributes":{"id":7,"target_branch":"master","source_branch":"test","source_project_id":98,"author_id":3,"assignee_id":null,"title":"test","created_at":"2016-01-20 21:47:23 UTC","updated_at":"2016-01-20 21:47:23 UTC","milestone_id":null,"state":"opened","merge_status":"unchecked","target_project_id":98,"iid":1,"description":"testing webhook","position":0,"locked_at":null,"updated_by_id":null,"merge_error":null,"merge_params":{},"merge_when_build_succeeds":false,"merge_user_id":null,"source":{"name":"g","ssh_url":"git@git.s7t.de:root/g.git","http_url":"https://git.s7t.de/root/g.git","web_url":"https://git.s7t.de/root/g","namespace":"ManiacTwister","visibility_level":0},"target":{"name":"g","ssh_url":"git@git.s7t.de:root/g.git","http_url":"https://git.s7t.de/root/g.git","web_url":"https://git.s7t.de/root/g","namespace":"ManiacTwister","visibility_level":0},"last_commit":{"id":"7ed279163735b6215fc30f893b5fba087bfe3079","message":"test","timestamp":"2016-01-20T22:46:50+01:00","url":"https://git.s7t.de/root/g/commit/7ed279163735b6215fc30f893b5fba087bfe3079","author":{"name":"ManiacTwister","email":"git@s7t.de"}},"work_in_progress":false,"url":"https://git.s7t.de/root/g/merge_requests/1","action":"open"}}
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