From 4d5b26642ec9b6fef079a8dab3b33b41350bc4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Danyi?= Date: Thu, 19 Jul 2018 16:14:44 +0200 Subject: [PATCH] * epicName added --- src/App/Entity/KanbanEntry.php | 25 +++++++++++ src/App/Service/JiraCollectorService.php | 55 ++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/src/App/Entity/KanbanEntry.php b/src/App/Entity/KanbanEntry.php index 1dbb401..22b8f27 100644 --- a/src/App/Entity/KanbanEntry.php +++ b/src/App/Entity/KanbanEntry.php @@ -130,6 +130,12 @@ class KanbanEntry implements \JsonSerializable */ private $taurusPrio = 9001; + /** + * JIRA: customfield_10004 in task in customfield_10001 of parent + * @var string + */ + private $epicName; + /** * @var int */ @@ -598,6 +604,24 @@ class KanbanEntry implements \JsonSerializable return $this; } + /** + * @return string + */ + public function getEpicName(): ?string + { + return $this->epicName; + } + + /** + * @param string $epicName + * @return KanbanEntry + */ + public function setEpicName(?string $epicName): KanbanEntry + { + $this->epicName = $epicName; + return $this; + } + /** * @return int */ @@ -662,6 +686,7 @@ class KanbanEntry implements \JsonSerializable 'key' => $this->getKey(), 'summary' => $this->getSummary(), 'issueType' => $this->getIssueType(), + 'epicName' => $this->getEpicName(), 'status' => $this->getStatus(), 'assignee' => $this->getAssignee(), 'additionalAssignees' => $this->getAdditionalAssignees()->getValues(), diff --git a/src/App/Service/JiraCollectorService.php b/src/App/Service/JiraCollectorService.php index c520ffb..4fb31e1 100644 --- a/src/App/Service/JiraCollectorService.php +++ b/src/App/Service/JiraCollectorService.php @@ -31,6 +31,9 @@ class JiraCollectorService /** @var RouterInterface */ private $router; + /** @var array */ + private $cachedEpics = []; + /** * JiraClientService constructor. * @param StorageInterface $cache @@ -125,6 +128,51 @@ class JiraCollectorService return $kanbanBoard; } + /** + * @param string $parentKey + * @return null|string + */ + private function getEpicNameFromParent(string $parentKey): ?string + { + if(array_key_exists($parentKey, $this->cachedEpics)) { + return $this->cachedEpics[$parentKey]; + } + + $user = $this->config->get('jira.user'); + $password = $this->config->get('jira.password'); + /** @var Config $kanbanBoardUriParams */ + $jiraIssueBaseUrl = $this->config->get('url.jiraIssue'); + $jiraIssueUri = sprintf($jiraIssueBaseUrl, $parentKey); + + $response = $this->httpClient + ->setUri($jiraIssueUri) + ->setAuth($user, $password) + ->send(); + + if (!$response->isSuccess()) { + throw new \UnexpectedValueException("Bad JIRA result", $response->getStatusCode()); + } + + $parsedJsonParentData = Decoder::decode($response->getBody(), Json::TYPE_ARRAY); + if ($parsedJsonParentData['fields']['customfield_10001']) { + $jiraIssueUri = sprintf($jiraIssueBaseUrl, $parsedJsonParentData['fields']['customfield_10001']); + $response = $this->httpClient + ->setUri($jiraIssueUri) + ->setAuth($user, $password) + ->send(); + + if (!$response->isSuccess()) { + throw new \UnexpectedValueException("Bad JIRA result", $response->getStatusCode()); + } + + $parsedJsonEpicData = Decoder::decode($response->getBody(), Json::TYPE_ARRAY); + $this->cachedEpics[$parentKey] = $parsedJsonEpicData['fields']['customfield_10004']; + return $this->cachedEpics[$parentKey]; + } + $this->cachedEpics[$parentKey] = null; + return null; + } + /** * @param $parsedJsonData * @return KanbanBoard @@ -135,6 +183,7 @@ class JiraCollectorService $kanbanBoard = new KanbanBoard(); foreach ($parsedJsonData['issues'] as $jsonIssue) { + set_time_limit(30); $kanbanEntry = new KanbanEntry(); $kanbanEntry->setId(intval($jsonIssue['id'])) ->setKey($jsonIssue['key']) @@ -180,6 +229,12 @@ class JiraCollectorService } } + // epicName: has parent, and parent has customfield_10001 + if (isset($jsonIssue['fields']['parent'])) { + $epicName = $this->getEpicNameFromParent($jsonIssue['fields']['parent']['key']); + $kanbanEntry->setEpicName($epicName); + } + // externalId : customfield_10010 if (isset($jsonIssue['fields']['customfield_10010'])) { $kanbanEntry->setExternalId($jsonIssue['fields']['customfield_10010']);