support 'Next Action Date'
This commit is contained in:
44
oncall.php
44
oncall.php
@@ -51,7 +51,23 @@ class oncall {
|
||||
* An array containing queries we want to run, with a label as a key.
|
||||
* @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.
|
||||
@@ -80,12 +96,6 @@ class oncall {
|
||||
$this->debugMode = (bool) getenv('DEBUG_MODE');
|
||||
$this->baseUrl = getenv('REDMINE_URL');
|
||||
$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,16 +127,26 @@ class oncall {
|
||||
* Get items from Redmine.
|
||||
*/
|
||||
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
|
||||
$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 (!empty($json)) {
|
||||
// go through this loop for each ticket found
|
||||
foreach ($json['issues'] as $k => $item) {
|
||||
foreach ($json['issues'] as $item) {
|
||||
if ($query['calculate_minutes']) {
|
||||
$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['author']['name']} ";
|
||||
$table .= "| {$item['subject']} ";
|
||||
$table .= "| {$item['minutes']} ";
|
||||
$table .= '| ' . $item['minutes'] ?? '' . ' ';
|
||||
if ($item['minutes'] ?? FALSE) {
|
||||
$table .= "| [Do Not Alert](https://oncall.megaphonetech.com/update_redmine.php?action=do_not_alert&issue={$item['id']}) ";
|
||||
}
|
||||
$table .= "|\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user