Skip to content

Instantly share code, notes, and snippets.

@jbrooksuk
Created August 14, 2012 09:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbrooksuk/3347914 to your computer and use it in GitHub Desktop.
Save jbrooksuk/3347914 to your computer and use it in GitHub Desktop.
Bugify External Hook URL - Pushover
<?php
/**
* Bugify External Hook URL with Pushover.
* @author James Brooks <jbrooksuk@me.com>
*/
if(!isset($_POST['payload'])) die('Error.');
// You don't need to change this bit.
define('PO_APIKEY', '4Kj8XLQrE4qdUiZwxY6giX33oQrDCq');
// Change this to match your user ID. Sign up at http://pushover.net
define('PO_USERKEY', 'XdceGa3YxczwaRmEHJhkAimQqywQd2');
// $_PayLoad = json_decode(file_get_contents('payload.json'));
$_PayLoad = json_decode(urldecode($_POST['payload']));
$oIssue = $_PayLoad->issue;
$issueTitle = $oIssue->subject;
$issueUpdated = strtotime($oIssue->updated);
$issueID = $oIssue->id;
$issuePriority = $oIssue->priority;
$issueDescription = substr($oIssue->description, 0, 128);
$aURL = array();
$aURL['url'] = $_SERVER['HTTP_REFERER'];
$aURL['title'] = $issueTitle;
$historyChanges = $_PayLoad->history->changes[0];
$historyDescription = $historyChanges->description;
$historyNew = substr($historyChanges->new, 0, 128);
$historyTitle = $historyChanges->title;
$historyUser = $_PayLoad->history->user->firstname;
$historyDate = strtotime($_PayLoad->history->created);
// If we've changed the progress, we want to use the description, it makes more sense.
$historyMessage = ($historyChanges->type == 6 ? $historyDescription : $historyNew);
// If we've added a new issue, use the actual issue data
$historyMessage = ($historyChanges->type == 12 ? "*{$issueTitle}*" . "\n{$issueDescription}" : $historyMessage);
$pushoverMsg = sprintf("%s %s:\n%s", $historyUser, strtolower($historyTitle), $historyMessage);
sendPushover("Bugify", $pushoverMsg, $aURL, $issuePriority);
function sendPushover($sTitle, $sMessage, $aURL, $iPriority = 1) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.pushover.net/1/messages");
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'token' => PO_APIKEY,
'user' => PO_USERKEY,
'title' => $sTitle,
'message' => $sMessage,
'url' => $aURL['url'],
'url_title' => $aURL['title'],
'priority' => $iPriority
));
curl_exec($ch);
curl_close($ch);
}
?>
@jbrooksuk
Copy link
Author

Completely forgot to include the date/time, but since Pushover timestamps messages, is there a real need?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment