add date/time/holiday check
This commit is contained in:
parent
26c0032053
commit
7726384a2c
@ -3,8 +3,8 @@
|
||||
"description": "A script to report on Redmine tickets that need attention.",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"kbsali/redmine-api": "^1.5",
|
||||
"vlucas/phpdotenv": "^4.1"
|
||||
"vlucas/phpdotenv": "^4.1",
|
||||
"azuyalabs/yasumi": "^2.2"
|
||||
},
|
||||
"license": "GPL",
|
||||
"authors": [
|
||||
|
50
composer.lock
generated
50
composer.lock
generated
@ -4,36 +4,39 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "9d1110731b1633c82d10df7e5b5077a6",
|
||||
"content-hash": "4a06e0b1ef6a70cff8f6b363a0c3f4bc",
|
||||
"packages": [
|
||||
{
|
||||
"name": "kbsali/redmine-api",
|
||||
"version": "v1.5.21",
|
||||
"name": "azuyalabs/yasumi",
|
||||
"version": "2.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/kbsali/php-redmine-api.git",
|
||||
"reference": "e75295b81e5dc4c858007d8924408e11e49e080c"
|
||||
"url": "https://github.com/azuyalabs/yasumi.git",
|
||||
"reference": "87cde7fd22e3e6e3ace9830b145b6a77338757e6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/kbsali/php-redmine-api/zipball/e75295b81e5dc4c858007d8924408e11e49e080c",
|
||||
"reference": "e75295b81e5dc4c858007d8924408e11e49e080c",
|
||||
"url": "https://api.github.com/repos/azuyalabs/yasumi/zipball/87cde7fd22e3e6e3ace9830b145b6a77338757e6",
|
||||
"reference": "87cde7fd22e3e6e3ace9830b145b6a77338757e6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"ext-simplexml": "*",
|
||||
"php": "^5.4 || ^7.2"
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^2.0",
|
||||
"phpunit/phpunit": "^4.8.36 || ^5.4.8 || ^6.0"
|
||||
"friendsofphp/php-cs-fixer": "^2.14",
|
||||
"fzaninotto/faker": "~1.8",
|
||||
"mikey179/vfsstream": "~1.6",
|
||||
"phpunit/phpunit": "~8.4"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-calendar": "For calculating the date of Easter"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Redmine\\": "src/Redmine/"
|
||||
"Yasumi\\": "src/Yasumi/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
@ -42,18 +45,23 @@
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Kevin Saliou",
|
||||
"email": "kevin@saliou.name",
|
||||
"homepage": "http://kevin.saliou.name"
|
||||
"name": "Sacha Telgenhof",
|
||||
"email": "me@sachatelgenhof.com"
|
||||
}
|
||||
],
|
||||
"description": "Redmine API client",
|
||||
"homepage": "https://github.com/kbsali/php-redmine-api",
|
||||
"description": "Yasumi is an easy PHP Library for calculating national holidays.",
|
||||
"keywords": [
|
||||
"api",
|
||||
"redmine"
|
||||
"Bank",
|
||||
"calculation",
|
||||
"calendar",
|
||||
"celebration",
|
||||
"date",
|
||||
"holiday",
|
||||
"holidays",
|
||||
"national",
|
||||
"time"
|
||||
],
|
||||
"time": "2019-03-15T17:37:16+00:00"
|
||||
"time": "2019-10-06T03:09:18+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoption/phpoption",
|
||||
|
60
oncall.php
60
oncall.php
@ -3,17 +3,11 @@
|
||||
declare(strict_types = 1);
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
use Yasumi\Holiday;
|
||||
|
||||
/* On Call Ticket Notification Script */
|
||||
|
||||
$today = date('Ymd');
|
||||
$holidays = array(20151126, 20151127, 20151225, 20160101, 20160118, 20160215, 20160530, 20160704, 20160905, 20161010, 20161111, 20161124);
|
||||
|
||||
if (in_array($today, $holidays)) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$oncall = new oncall();
|
||||
$oncall->dateAndTimeCheck();
|
||||
$oncall->retrieveItems();
|
||||
$oncall->setEmail();
|
||||
$table = $oncall->buildMattermostTable();
|
||||
@ -35,10 +29,10 @@ class oncall {
|
||||
private $debugMode = FALSE;
|
||||
|
||||
/**
|
||||
* A flag to indicate at least one ticket is overdue.
|
||||
* A flag to indicate that everyone should be notified.
|
||||
* @var bool
|
||||
*/
|
||||
private $overdue = FALSE;
|
||||
private $everyone = FALSE;
|
||||
|
||||
/**
|
||||
* The URL of the Redmine install.
|
||||
@ -88,7 +82,7 @@ class oncall {
|
||||
|
||||
/**
|
||||
* Add the number of minutes since a ticket was created.
|
||||
* Also set the overdue flag if necessary.
|
||||
* Also set the everyone flag if necessary.
|
||||
*/
|
||||
private function getMinutes(array $item) {
|
||||
// find the time since the ticket was created
|
||||
@ -103,7 +97,7 @@ class oncall {
|
||||
$item['minutes'] = $td_min;
|
||||
// Flag if any items are overdue.
|
||||
if ($td_min > 60) {
|
||||
$this->overdue = TRUE;
|
||||
$this->everyone = TRUE;
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
@ -174,11 +168,11 @@ class oncall {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Mattermost name from email, or "@channel" if there's an overdue ticket.
|
||||
* Return a Mattermost name from email, or "@channel" if there's an everyone ticket.
|
||||
* @return string
|
||||
*/
|
||||
private function findMattermostName() {
|
||||
if ($this->overdue) {
|
||||
if ($this->everyone) {
|
||||
return 'channel';
|
||||
}
|
||||
// Check users.csv column 1 for email; return column 2 if it matches.
|
||||
@ -201,6 +195,44 @@ class oncall {
|
||||
$this->email = trim(file_get_contents("$contactfile"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether we're responsible for on-call on this date and time.
|
||||
*/
|
||||
public function dateAndTimeCheck() {
|
||||
$today = new DateTime();
|
||||
$thisYear = (int) $today->format('Y');
|
||||
$thisHour = (int) $today->formay('H');
|
||||
|
||||
// Time check.
|
||||
if ($thisHour < 10 || $thisHour > 20) {
|
||||
// After hours.
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$holidays = Yasumi\Yasumi::create('USA', $thisYear);
|
||||
$holidays->removeHoliday('columbusDay');
|
||||
$holidays->addHoliday(new Holiday('indigenousPeoplesDay', [
|
||||
'en' => 'Indigenous People\'s Day',
|
||||
], new DateTime("second monday of october $thisYear", new DateTimeZone('America/New_York'))));
|
||||
$holidays->addHoliday(new Holiday('dayAfterThanksgiving', [
|
||||
'en' => 'Day After Thanksgiving',
|
||||
], new DateTime("fourth friday of november $thisYear", new DateTimeZone('America/New_York'))));
|
||||
|
||||
// Is today a holiday?
|
||||
if ($holidays->isHoliday($today)) {
|
||||
$this->everyone = TRUE;
|
||||
$todaysHoliday = $holidays->on($today);
|
||||
print_r($todaysHoliday);
|
||||
die;
|
||||
$this->sendToMattermost("Happy $holidayName Megaphone Tech! There is no on-call today.")
|
||||
}
|
||||
// Don't do anything else if it's a holiday or weekend.
|
||||
if (!$holidays->isWorkingDay($today))) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user