Page MenuHomeDevCentral

JenkinsNotification.php
No OneTemporary

JenkinsNotification.php

<?php
namespace Nasqueron\Notifications\Notifications;
use Nasqueron\Notifications\Notification;
/**
* A Jenkins notification.
*
* This handles the JSON payloads sent by the following plugin:
* https://wiki.jenkins-ci.org/display/JENKINS/Notification+Plugin
*/
class JenkinsNotification extends Notification {
/**
* Initializes a new instance of the JenkinsNotification class.
*
* @param string $project The project this message is for
* @param mixed $payload The message fired by Jenkins notification plugin
*/
public function __construct ($project, $payload) {
// Straightforward properties
$this->service = "Jenkins";
$this->project = $project;
$this->rawContent = $payload;
// Properties from the payload
$this->group = $this->getGroup();
$this->text = $this->getText();
$this->link = $payload->build->full_url;
$this->type = $this->getType();
}
/**
* Gets the notification type.
*
* @return string
*/
public function getType () {
$build = $this->rawContent->build;
$type = strtolower($build->phase);
if (property_exists($build, 'status')) {
$type .= '.';
$type .= $build->status;
}
return strtolower($type);
}
/**
* Gets the notification text. Intended to convey a short message (thing Twitter or IRC).
*
* @return string
*/
public function getText () {
$name = $this->rawContent->name;
$build = $this->rawContent->build;
$phase = strtolower($build->phase);
$text = "Jenkins job $name has been $phase";
if (property_exists($build, 'status')) {
$status = strtolower($build->status);
$text .= ": $status";
}
return $text;
}
/**
* Gets the notification group.
*
* @return string
*/
public function getGroup () {
return "ci"; // This is a temporary group, intended before mapping.
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Feb 28, 21:45 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2437540
Default Alt Text
JenkinsNotification.php (2 KB)

Event Timeline