* avatar overrides added
* cli commands framework added * labinfo service for lab temp monitoring * kanban entry label support
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
namespace App\Action;
|
||||
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\DataCollectorService;
|
||||
use App\Service\JiraCollectorService;
|
||||
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
@@ -12,7 +12,7 @@ class KanbanAction implements ServerMiddlewareInterface
|
||||
{
|
||||
private $dataCollector;
|
||||
|
||||
public function __construct(DataCollectorService $dataCollectorService)
|
||||
public function __construct(JiraCollectorService $dataCollectorService)
|
||||
{
|
||||
$this->dataCollector = $dataCollectorService;
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace App\Action;
|
||||
|
||||
use App\Service\DataCollectorService;
|
||||
use App\Service\JiraCollectorService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class KanbanFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$dataCollectorService = $container->get(DataCollectorService::class);
|
||||
$dataCollectorService = $container->get(JiraCollectorService::class);
|
||||
return new KanbanAction($dataCollectorService);
|
||||
}
|
||||
}
|
||||
|
||||
33
src/App/Command/UpdateLabInfoCommand.php
Normal file
33
src/App/Command/UpdateLabInfoCommand.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\LabInfoCollectorService;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class UpdateLabInfoCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var LabInfoCollectorService
|
||||
*/
|
||||
private $labInfoService;
|
||||
|
||||
public function __construct(LabInfoCollectorService $labInfoService)
|
||||
{
|
||||
$this->labInfoService = $labInfoService;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('labinfo:print')
|
||||
->setDescription('Updates cache of jcat packages, streams and active nightly ci configuration');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$output->writeln($this->labInfoService->getLabTemperatureData());
|
||||
}
|
||||
}
|
||||
16
src/App/Command/UpdateLabInfoFactory.php
Normal file
16
src/App/Command/UpdateLabInfoFactory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Service\LabInfoCollectorService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class UpdateLabInfoFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
/** @var LabInfoCollectorService $labInfoService */
|
||||
$labInfoService = $container->get(LabInfoCollectorService::class);
|
||||
return new UpdateLabInfoCommand($labInfoService);
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,8 @@ class ConfigProvider
|
||||
Action\KanbanAction::class => Action\KanbanFactory::class,
|
||||
|
||||
Service\AvatarService::class => Service\AvatarServiceFactory::class,
|
||||
Service\DataCollectorService::class => Service\DataCollectorServiceFactory::class,
|
||||
Service\JiraCollectorService::class => Service\JiraCollectorServiceFactory::class,
|
||||
Service\LabInfoCollectorService::class => Service\LabInfoCollectorServiceFactory::class,
|
||||
|
||||
'service.avatarCache' => function(ContainerInterface $container): StorageInterface {
|
||||
$cache = new FilesytemCache();
|
||||
@@ -65,11 +66,18 @@ class ConfigProvider
|
||||
|
||||
$httpClient = new Client();
|
||||
$httpClient->setAdapter($curlAdapter = new Client\Adapter\Curl());
|
||||
$curlAdapter->setOptions(['timeout' => 300]);
|
||||
$curlAdapter->setOptions([
|
||||
'timeout' => 300,
|
||||
]);
|
||||
$curlAdapter
|
||||
->setCurlOption(CURLOPT_SSL_VERIFYPEER, false)
|
||||
->setCurlOption(CURLOPT_SSL_VERIFYHOST, false)
|
||||
;
|
||||
if($config->get('http.proxy.enabled', false)) {
|
||||
$curlAdapter
|
||||
->setCurlOption(CURLOPT_PROXYTYPE, $config->get('http.proxy.type'))
|
||||
->setCurlOption(CURLOPT_PROXY, $config->get('http.proxy.url'));
|
||||
->setCurlOption(CURLOPT_PROXY, $config->get('http.proxy.url'))
|
||||
;
|
||||
}
|
||||
return $httpClient;
|
||||
},
|
||||
|
||||
@@ -47,6 +47,11 @@ class KanbanEntry implements \JsonSerializable
|
||||
*/
|
||||
private $issuePriorityIcon;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $labels;
|
||||
|
||||
/**
|
||||
* JIRA: customfield_11226
|
||||
* @var int
|
||||
@@ -277,6 +282,24 @@ class KanbanEntry implements \JsonSerializable
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getLabels(): ?array
|
||||
{
|
||||
return $this->labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $labels
|
||||
* @return KanbanEntry
|
||||
*/
|
||||
public function setLabels(?array $labels): KanbanEntry
|
||||
{
|
||||
$this->labels = $labels;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]|ArrayCollection
|
||||
*/
|
||||
@@ -477,6 +500,7 @@ class KanbanEntry implements \JsonSerializable
|
||||
'assignee' => $this->getAssignee(),
|
||||
'issuePriority' => $this->getIssuePriority(),
|
||||
'issuePriorityIcon' => $this->getIssuePriorityIcon(),
|
||||
'labels' => $this->getLabels(),
|
||||
'prio' => $this->getPrio(),
|
||||
'functionalArea' => $this->getFunctionalAreas()->getValues(),
|
||||
'externalId' => $this->getExternalId(),
|
||||
|
||||
@@ -12,7 +12,7 @@ use Zend\Http\Client;
|
||||
use Zend\Json\Decoder;
|
||||
use Zend\Json\Json;
|
||||
|
||||
class DataCollectorService
|
||||
class JiraCollectorService
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
@@ -89,6 +89,7 @@ class DataCollectorService
|
||||
->setAnswerCode($jsonIssue['fields']['customfield_11692'])
|
||||
->setIssuePriority($jsonIssue['fields']['priority']['name'])
|
||||
->setIssuePriorityIcon($jsonIssue['fields']['priority']['iconUrl'])
|
||||
->setLabels($jsonIssue['fields']['labels'])
|
||||
;
|
||||
|
||||
// externalId : customfield_10010
|
||||
@@ -6,7 +6,7 @@ use Interop\Container\ContainerInterface;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Http\Client;
|
||||
|
||||
class DataCollectorServiceFactory
|
||||
class JiraCollectorServiceFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
@@ -14,6 +14,6 @@ class DataCollectorServiceFactory
|
||||
$httpClient = $container->get(Client::class);
|
||||
$config = new Config($configArray['app.config']);
|
||||
$avatarService = $container->get(AvatarService::class);
|
||||
return new DataCollectorService($httpClient, $config, $avatarService);
|
||||
return new JiraCollectorService($httpClient, $config, $avatarService);
|
||||
}
|
||||
}
|
||||
86
src/App/Service/LabInfoCollectorService.php
Normal file
86
src/App/Service/LabInfoCollectorService.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Symfony\Component\CssSelector\CssSelectorConverter;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Http\Client;
|
||||
|
||||
class LabInfoCollectorService
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
private $httpClient;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $tempSensors = [
|
||||
'Temp 5' => 'back_left',
|
||||
'Temp 4' => 'back_middle',
|
||||
'Temp 3' => 'back_right',
|
||||
];
|
||||
|
||||
/**
|
||||
* JiraClientService constructor.
|
||||
* @param Client $client
|
||||
* @param Config $config
|
||||
*/
|
||||
public function __construct(Client $client, Config $config)
|
||||
{
|
||||
$this->httpClient = $client;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function getLabTemperatureData()
|
||||
{
|
||||
/** @var Config $labTemperatureUrl */
|
||||
$labTemperatureUrl = $this->config->get('url.labTemperatureUrl');
|
||||
|
||||
$response = $this->httpClient
|
||||
->setUri($labTemperatureUrl)
|
||||
->send();
|
||||
|
||||
if(!$response->isSuccess()) {
|
||||
throw new \UnexpectedValueException("Bad LAB result", $response->getStatusCode());
|
||||
}
|
||||
|
||||
return $this->parseHtml($response->getBody());
|
||||
}
|
||||
|
||||
private function parseHtml($html): array
|
||||
{
|
||||
$cssToXpathConverter = new CssSelectorConverter();
|
||||
$xpathLabelQuery = $cssToXpathConverter->toXPath('a.sensormenu.isnotpaused');
|
||||
$xpathValueQuery = $cssToXpathConverter->toXPath('div.graphlabel2');
|
||||
|
||||
$xmlErrorHandling = libxml_use_internal_errors(TRUE);
|
||||
$domDocument = new \DOMDocument();
|
||||
$domDocument->loadHTML($html);
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors($xmlErrorHandling);
|
||||
|
||||
$documentXpath = new \DOMXPath($domDocument);
|
||||
/** @var \DOMNodeList $element */
|
||||
$element = $documentXpath->query($xpathLabelQuery);
|
||||
|
||||
$thing = [];
|
||||
/** @var \DOMElement $item */
|
||||
foreach($element as $item) {
|
||||
$sensorName = trim($item->nodeValue);
|
||||
if( in_array($sensorName, array_keys($this->tempSensors)) ){
|
||||
/** @var \DOMNodeList $element */
|
||||
$valueElement = $documentXpath->query($xpathValueQuery, $item->parentNode->parentNode);
|
||||
$thing[$this->tempSensors[$sensorName]] = $valueElement->item(0)->nodeValue;
|
||||
}
|
||||
}
|
||||
|
||||
return $thing;
|
||||
}
|
||||
}
|
||||
18
src/App/Service/LabInfoCollectorServiceFactory.php
Normal file
18
src/App/Service/LabInfoCollectorServiceFactory.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Http\Client;
|
||||
|
||||
class LabInfoCollectorServiceFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$configArray = $container->get('config');
|
||||
$httpClient = $container->get(Client::class);
|
||||
$config = new Config($configArray['app.config']);
|
||||
return new LabInfoCollectorService($httpClient, $config);
|
||||
}
|
||||
}
|
||||
86
src/App/Service/TrInfoCollectorService.php
Normal file
86
src/App/Service/TrInfoCollectorService.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Symfony\Component\CssSelector\CssSelectorConverter;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Http\Client;
|
||||
|
||||
class TrInfoCollectorService
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
private $httpClient;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $tempSensors = [
|
||||
'Temp 5' => 'back_left',
|
||||
'Temp 4' => 'back_middle',
|
||||
'Temp 3' => 'back_right',
|
||||
];
|
||||
|
||||
/**
|
||||
* JiraClientService constructor.
|
||||
* @param Client $client
|
||||
* @param Config $config
|
||||
*/
|
||||
public function __construct(Client $client, Config $config)
|
||||
{
|
||||
$this->httpClient = $client;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function getLabTemperatureData()
|
||||
{
|
||||
/** @var Config $labTemperatureUrl */
|
||||
$labTemperatureUrl = $this->config->get('url.labTemperatureUrl');
|
||||
|
||||
$response = $this->httpClient
|
||||
->setUri($labTemperatureUrl)
|
||||
->send();
|
||||
|
||||
if(!$response->isSuccess()) {
|
||||
throw new \UnexpectedValueException("Bad LAB result", $response->getStatusCode());
|
||||
}
|
||||
|
||||
return $this->parseHtml($response->getBody());
|
||||
}
|
||||
|
||||
private function parseHtml($html): array
|
||||
{
|
||||
$cssToXpathConverter = new CssSelectorConverter();
|
||||
$xpathLabelQuery = $cssToXpathConverter->toXPath('a.sensormenu.isnotpaused');
|
||||
$xpathValueQuery = $cssToXpathConverter->toXPath('div.graphlabel2');
|
||||
|
||||
$xmlErrorHandling = libxml_use_internal_errors(TRUE);
|
||||
$domDocument = new \DOMDocument();
|
||||
$domDocument->loadHTML($html);
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors($xmlErrorHandling);
|
||||
|
||||
$documentXpath = new \DOMXPath($domDocument);
|
||||
/** @var \DOMNodeList $element */
|
||||
$element = $documentXpath->query($xpathLabelQuery);
|
||||
|
||||
$thing = [];
|
||||
/** @var \DOMElement $item */
|
||||
foreach($element as $item) {
|
||||
$sensorName = trim($item->nodeValue);
|
||||
if( in_array($sensorName, array_keys($this->tempSensors)) ){
|
||||
/** @var \DOMNodeList $element */
|
||||
$valueElement = $documentXpath->query($xpathValueQuery, $item->parentNode->parentNode);
|
||||
$thing[$this->tempSensors[$sensorName]] = $valueElement->item(0)->nodeValue;
|
||||
}
|
||||
}
|
||||
|
||||
return $thing;
|
||||
}
|
||||
}
|
||||
18
src/App/Service/TrInfoCollectorServiceFactory.php
Normal file
18
src/App/Service/TrInfoCollectorServiceFactory.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Http\Client;
|
||||
|
||||
class TrInfoCollectorServiceFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$configArray = $container->get('config');
|
||||
$httpClient = $container->get(Client::class);
|
||||
$config = new Config($configArray['app.config']);
|
||||
return new TrInfoCollectorService($httpClient, $config);
|
||||
}
|
||||
}
|
||||
86
src/App/Service/VacationInfoCollectorService.php
Normal file
86
src/App/Service/VacationInfoCollectorService.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Symfony\Component\CssSelector\CssSelectorConverter;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Http\Client;
|
||||
|
||||
class VacationInfoCollectorService
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
private $httpClient;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $tempSensors = [
|
||||
'Temp 5' => 'back_left',
|
||||
'Temp 4' => 'back_middle',
|
||||
'Temp 3' => 'back_right',
|
||||
];
|
||||
|
||||
/**
|
||||
* JiraClientService constructor.
|
||||
* @param Client $client
|
||||
* @param Config $config
|
||||
*/
|
||||
public function __construct(Client $client, Config $config)
|
||||
{
|
||||
$this->httpClient = $client;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function getLabTemperatureData()
|
||||
{
|
||||
/** @var Config $labTemperatureUrl */
|
||||
$labTemperatureUrl = $this->config->get('url.labTemperatureUrl');
|
||||
|
||||
$response = $this->httpClient
|
||||
->setUri($labTemperatureUrl)
|
||||
->send();
|
||||
|
||||
if(!$response->isSuccess()) {
|
||||
throw new \UnexpectedValueException("Bad LAB result", $response->getStatusCode());
|
||||
}
|
||||
|
||||
return $this->parseHtml($response->getBody());
|
||||
}
|
||||
|
||||
private function parseHtml($html): array
|
||||
{
|
||||
$cssToXpathConverter = new CssSelectorConverter();
|
||||
$xpathLabelQuery = $cssToXpathConverter->toXPath('a.sensormenu.isnotpaused');
|
||||
$xpathValueQuery = $cssToXpathConverter->toXPath('div.graphlabel2');
|
||||
|
||||
$xmlErrorHandling = libxml_use_internal_errors(TRUE);
|
||||
$domDocument = new \DOMDocument();
|
||||
$domDocument->loadHTML($html);
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors($xmlErrorHandling);
|
||||
|
||||
$documentXpath = new \DOMXPath($domDocument);
|
||||
/** @var \DOMNodeList $element */
|
||||
$element = $documentXpath->query($xpathLabelQuery);
|
||||
|
||||
$thing = [];
|
||||
/** @var \DOMElement $item */
|
||||
foreach($element as $item) {
|
||||
$sensorName = trim($item->nodeValue);
|
||||
if( in_array($sensorName, array_keys($this->tempSensors)) ){
|
||||
/** @var \DOMNodeList $element */
|
||||
$valueElement = $documentXpath->query($xpathValueQuery, $item->parentNode->parentNode);
|
||||
$thing[$this->tempSensors[$sensorName]] = $valueElement->item(0)->nodeValue;
|
||||
}
|
||||
}
|
||||
|
||||
return $thing;
|
||||
}
|
||||
}
|
||||
18
src/App/Service/VacationInfoCollectorServiceFactory.php
Normal file
18
src/App/Service/VacationInfoCollectorServiceFactory.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Http\Client;
|
||||
|
||||
class VacationInfoCollectorServiceFactory
|
||||
{
|
||||
public function __invoke(ContainerInterface $container)
|
||||
{
|
||||
$configArray = $container->get('config');
|
||||
$httpClient = $container->get(Client::class);
|
||||
$config = new Config($configArray['app.config']);
|
||||
return new VacationInfoCollectorService($httpClient, $config);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user