Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4793476
JenkinsNotification.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
JenkinsNotification.php
View Options
<?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
Details
Attached
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)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment