-
Notifications
You must be signed in to change notification settings - Fork 1
/
JiraActivityPlugin.php
60 lines (51 loc) · 1.98 KB
/
JiraActivityPlugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
declare(strict_types=1);
/*
* This file is part of forecast.it.fill project.
* (c) Patrick Jaja <[email protected]>
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace ForecastAutomation\JiraClient\Shared\Plugin;
use ForecastAutomation\Activity\Shared\Dto\ActivityDto;
use ForecastAutomation\Activity\Shared\Dto\ActivityDtoCollection;
use ForecastAutomation\Activity\Shared\Plugin\ActivityPluginInterface;
use ForecastAutomation\Kernel\Shared\Plugin\AbstractPlugin;
use GuzzleHttp\Promise\Promise;
use GuzzleHttp\Promise\PromiseInterface;
/**
* @method \ForecastAutomation\JiraClient\JiraClientFacade getFacade()
*/
class JiraActivityPlugin extends AbstractPlugin implements ActivityPluginInterface
{
public const ACTIVITY_DURATION = 30;
public const COMMENT_IDENTIFIER = 'Ticket Bearbeitung';
public function collect(): PromiseInterface
{
$wrapPromise = new Promise(
function () use (&$wrapPromise) {
$comments = $this->getFacade()->getComments(date('Y-m-d 00:00'));
$wrapPromise->resolve($this->createActivityDtoCollection($comments));
}
);
return $wrapPromise;
}
private function createActivityDtoCollection(array $jiraComments): ActivityDtoCollection
{
$activityDtoArray = [];
foreach ($jiraComments as $jiraTicketNumber => $jiraComment) {
$activityDtoArray[] = new ActivityDto(
$jiraTicketNumber,
sprintf(
'%s: %s - %s',
self::COMMENT_IDENTIFIER,
$jiraTicketNumber,
sprintf('%s...', substr(preg_replace('/\[[^)]+\]/', '', $jiraComment[0]->body), 0, 60))
),
$jiraComment[0]->updated,
self::ACTIVITY_DURATION * \count($jiraComment)
);
}
return new ActivityDtoCollection(...$activityDtoArray);
}
}