support 'Next Action Date'
This commit is contained in:
50
oncall.php
50
oncall.php
@@ -51,7 +51,23 @@ class oncall {
|
|||||||
* An array containing queries we want to run, with a label as a key.
|
* An array containing queries we want to run, with a label as a key.
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $queries;
|
private $queries = [
|
||||||
|
'New Support Tickets' => [
|
||||||
|
'url' => 'https://hq.megaphonetech.com/issues.json?query_id=17&key=7ebe204bef5804f4effb9b4160a295487dde15f1',
|
||||||
|
'calculate_minutes' => TRUE,
|
||||||
|
'show_once' => FALSE,
|
||||||
|
],
|
||||||
|
'New Maintenance Tickets' => [
|
||||||
|
'url' => 'https://hq.megaphonetech.com/issues.json?query_id=18&key=7ebe204bef5804f4effb9b4160a295487dde15f1',
|
||||||
|
'calculate_minutes' => TRUE,
|
||||||
|
'show_once' => FALSE,
|
||||||
|
],
|
||||||
|
'Next Action Alerts' => [
|
||||||
|
'url' => 'https://hq.megaphonetech.com/issues.json?query_id=19&key=7ebe204bef5804f4effb9b4160a295487dde15f1',
|
||||||
|
'calculate_minutes' => FALSE,
|
||||||
|
'show_once' => TRUE,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of the query results from Redmine. Key is the query label.
|
* An array of the query results from Redmine. Key is the query label.
|
||||||
@@ -80,12 +96,6 @@ class oncall {
|
|||||||
$this->debugMode = (bool) getenv('DEBUG_MODE');
|
$this->debugMode = (bool) getenv('DEBUG_MODE');
|
||||||
$this->baseUrl = getenv('REDMINE_URL');
|
$this->baseUrl = getenv('REDMINE_URL');
|
||||||
$this->apiKey = getenv('REDMINE_API_KEY');
|
$this->apiKey = getenv('REDMINE_API_KEY');
|
||||||
|
|
||||||
// FIXME: Not using $this->apiKey.
|
|
||||||
$this->queries = [
|
|
||||||
'New Support Tickets' => 'https://hq.megaphonetech.com/issues.json?query_id=17&key=7ebe204bef5804f4effb9b4160a295487dde15f1',
|
|
||||||
'New Maintenance Tickets' => 'https://hq.megaphonetech.com/issues.json?query_id=18&key=7ebe204bef5804f4effb9b4160a295487dde15f1',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,15 +127,25 @@ class oncall {
|
|||||||
* Get items from Redmine.
|
* Get items from Redmine.
|
||||||
*/
|
*/
|
||||||
public function retrieveItems() {
|
public function retrieveItems() {
|
||||||
foreach ($this->queries as $title => $url) {
|
foreach ($this->queries as $title => $query) {
|
||||||
// get the contents of the query in a usable format
|
// get the contents of the query in a usable format
|
||||||
$json = json_decode(file_get_contents($url), TRUE);
|
$json = json_decode(file_get_contents($query['url'] . "&key=$this->apiKey"), TRUE);
|
||||||
// if the query has any results
|
// if the query has any results
|
||||||
if (!empty($json)) {
|
if (!empty($json)) {
|
||||||
// go through this loop for each ticket found
|
// go through this loop for each ticket found
|
||||||
foreach ($json['issues'] as $k => $item) {
|
foreach ($json['issues'] as $item) {
|
||||||
$item['minutes'] = $this->calculateMinutes($item);
|
if ($query['calculate_minutes']) {
|
||||||
$this->queryResults[$title][] = $item;
|
$item['minutes'] = $this->calculateMinutes($item);
|
||||||
|
$this->queryResults[$title][] = $item;
|
||||||
|
}
|
||||||
|
if ($query['show_once']) {
|
||||||
|
// Show between 10am and 10:03am only.
|
||||||
|
if (1 || (date('H') == 10 && date('i') <= 3)) {
|
||||||
|
$item['minutes'] = NULL;
|
||||||
|
$this->notify = TRUE;
|
||||||
|
$this->queryResults[$title][] = $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,8 +167,10 @@ class oncall {
|
|||||||
$table .= "| {$item['project']['name']} ";
|
$table .= "| {$item['project']['name']} ";
|
||||||
$table .= "| {$item['author']['name']} ";
|
$table .= "| {$item['author']['name']} ";
|
||||||
$table .= "| {$item['subject']} ";
|
$table .= "| {$item['subject']} ";
|
||||||
$table .= "| {$item['minutes']} ";
|
$table .= '| ' . $item['minutes'] ?? '' . ' ';
|
||||||
$table .= "| [Do Not Alert](https://oncall.megaphonetech.com/update_redmine.php?action=do_not_alert&issue={$item['id']}) ";
|
if ($item['minutes'] ?? FALSE) {
|
||||||
|
$table .= "| [Do Not Alert](https://oncall.megaphonetech.com/update_redmine.php?action=do_not_alert&issue={$item['id']}) ";
|
||||||
|
}
|
||||||
$table .= "|\n";
|
$table .= "|\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user